<commit_before>/* eslint-disable no-unused-vars, no-param-reassign */
import { define, props } from 'skatejs';
import { h } from 'preact';
import URLSearchParams from '@ungap/url-search-params'; // URLSearchParams poly for older browsers
import render from 'preact-render-to-string';

import { store } from '../../store.js'; // connect to redux
import { updateCurrentPattern, updateCurrentUrl } from '../../actions/app.js'; // redux actions
import { updateViewportPx, updateViewportEm } from '../../actions/app.js'; // redux actions needed
import { minViewportWidth, maxViewportWidth } from '../../utils';
import { BaseComponent } from '../base-component.js';
import { urlHandler, patternName } from '../../utils';

import styles from '../../../sass/pattern-lab--iframe-loader.scss';

let trackingPageChange = false;

@define
class IFrame extends BaseComponent {
  static is = 'pl-iframe';

  constructor(self) {
    self = super(self);
    self.useShadow = false;
    self.usingBrowserNav = true;
    self._hasInitiallyRendered = false;
    self.fullMode = true;
    self.viewportResizeHandleWidth = 14; //Width of the viewport drag-to-resize handle
    self.bodySize =
      window.config.ishFontSize !== undefined
        ? parseInt(window.config.ishFontSize, 10)
        : parseInt(
            window
              .getComputedStyle(document.body, null)
              .getPropertyValue('font-size'),
            10
          ); //Body size of the document
    self.handlePageChange = self.handlePageChange.bind(self);
    self.handlePageLoad = self.handlePageLoad.bind(self);
    // self.receiveIframeMessage = self.receiveIframeMessage.bind(self);
    self.handleResize = self.handleResize.bind(self);
    self.handleMouseDown = self.handleMouseDown.bind(self);
    self.handleIframeLoaded = self.handleIframeLoaded.bind(self);
    //set up the default for the
    self.baseIframePath =
      window.location.protocol +
      '//' +
      window.location.host +
      window.location.pathname.replace('index.html', '');
    self.defaultIframePath = self.baseIframePath + '?p=components-overview';
    return self;
  }

  // update the currently active nav + add / update the page's query string
  handlePageLoad(e) {
    var queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    let patternParam = urlParams.get('p');

    if (e.detail.pattern) {
      document.title = 'Pattern Lab - ' + e.detail.pattern;

      const addressReplacement =
        window.location.protocol === 'file:'
          ? null
          : window.location.protocol +
            '//' +
            window.location.host +
            window.location.pathname.replace('index.html', '') +
            '?p=' +
            e.detail.pattern;

      // first time hitting a PL page -- no query string on the current page
      if (patternParam === null) {
        window.history.replaceState(
          {
            currentPattern: e.detail.pattern,
          },
          null,
          addressReplacement
        );
      } else {
        window.history.replaceState(
          {
            currentPattern: e.detail.pattern,
          },
          null,
          addressReplacement
        );
      }

      const currentUrl = urlHandler.getFileName(e.detail.pattern);

      // don't update state or upddate the URL for non-existent patterns
      if (currentUrl) {
        store.dispatch(updateCurrentPattern(e.detail.pattern));
        store.dispatch(updateCurrentUrl(currentUrl));
      }
    }
  }

  // navigate to the new PL page (based on the query string) when the page's pop state changes
  handlePageChange(e) {<commit_msg>fix: fall back to seeing the current pattern's query string to `all` or the defaultPattern value if undefined when the iframe page initially loads<commit_after>/* eslint-disable no-unused-vars, no-param-reassign */
import { define, props } from 'skatejs';
import { h } from 'preact';
import URLSearchParams from '@ungap/url-search-params'; // URLSearchParams poly for older browsers
import render from 'preact-render-to-string';

import { store } from '../../store.js'; // connect to redux
import { updateCurrentPattern, updateCurrentUrl } from '../../actions/app.js'; // redux actions
import { updateViewportPx, updateViewportEm } from '../../actions/app.js'; // redux actions needed
import { minViewportWidth, maxViewportWidth } from '../../utils';
import { BaseComponent } from '../base-component.js';
import { urlHandler, patternName } from '../../utils';

import styles from '../../../sass/pattern-lab--iframe-loader.scss';

let trackingPageChange = false;

@define
class IFrame extends BaseComponent {
  static is = 'pl-iframe';

  constructor(self) {
    self = super(self);
    self.useShadow = false;
    self.usingBrowserNav = true;
    self._hasInitiallyRendered = false;
    self.fullMode = true;
    self.viewportResizeHandleWidth = 14; //Width of the viewport drag-to-resize handle
    self.bodySize =
      window.config.ishFontSize !== undefined
        ? parseInt(window.config.ishFontSize, 10)
        : parseInt(
            window
              .getComputedStyle(document.body, null)
              .getPropertyValue('font-size'),
            10
          ); //Body size of the document
    self.handlePageChange = self.handlePageChange.bind(self);
    self.handlePageLoad = self.handlePageLoad.bind(self);
    // self.receiveIframeMessage = self.receiveIframeMessage.bind(self);
    self.handleResize = self.handleResize.bind(self);
    self.handleMouseDown = self.handleMouseDown.bind(self);
    self.handleIframeLoaded = self.handleIframeLoaded.bind(self);
    //set up the default for the
    self.baseIframePath =
      window.location.protocol +
      '//' +
      window.location.host +
      window.location.pathname.replace('index.html', '');
    self.defaultIframePath = self.baseIframePath + '?p=components-overview';
    return self;
  }

  // update the currently active nav + add / update the page's query string
  handlePageLoad(e) {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const patternParam = urlParams.get('p');

    const currentPattern =
      e.detail.pattern || window.config.defaultPattern || 'all';

    if (currentPattern) {
      document.title = 'Pattern Lab - ' + currentPattern;

      const addressReplacement =
        window.location.protocol === 'file:'
          ? null
          : window.location.protocol +
            '//' +
            window.location.host +
            window.location.pathname.replace('index.html', '') +
            '?p=' +
            currentPattern;

      // first time hitting a PL page -- no query string on the current page
      if (patternParam === null) {
        window.history.replaceState(
          {
            currentPattern: currentPattern,
          },
          null,
          addressReplacement
        );
      } else {
        window.history.replaceState(
          {
            currentPattern: currentPattern,
          },
          null,
          addressReplacement
        );
      }

      const currentUrl = urlHandler.getFileName(e.detail.pattern);

      // don't update state or upddate the URL for non-existent patterns
      if (currentUrl) {
        store.dispatch(updateCurrentPattern(e.detail.pattern));
        store.dispatch(updateCurrentUrl(currentUrl));
      }
    }
  }

  // navigate to the new PL page (based on the query string) when the page's pop state changes
  handlePageChange(e) {
{'fraction_non_alphanumeric': 0.1183651804670913, 'fraction_numerical': 0.0015923566878980893, 'mean_word_length': 2.556866446436999, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3635381', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2066, 'n_words': 506}