Repository: ianstormtaylor/slate
File: site/examples/js/huge-document.jsx (JavaScript)

Code before:
    : new URLSearchParams(document.location.search)
const parseNumber = (key, defaultValue) =>
  parseInt(searchParams?.get(key) ?? '', 10) || defaultValue
const parseBoolean = (key, defaultValue) => {
  const value = searchParams?.get(key)
  if (value) return value === 'true'
  return defaultValue
}
const parseEnum = (key, options, defaultValue) => {
  const value = searchParams?.get(key)
  if (value && options.includes(value)) return value
  return defaultValue
}
const initialConfig = {
  blocks: parseNumber('blocks', 10000),
  chunking: parseBoolean('chunking', true),
  chunkSize: parseNumber('chunk_size', 1000),
  chunkDivs: parseBoolean('chunk_divs', true),
  chunkOutlines: parseBoolean('chunk_outlines', false),
  contentVisibilityMode: parseEnum(
    'content_visibility',
    ['none', 'element', 'chunk'],
    'chunk'
  ),
  showSelectedHeadings: parseBoolean('selected_headings', false),
}
const setSearchParams = config => {
  if (searchParams) {
    searchParams.set('blocks', config.blocks.toString())
    searchParams.set('chunking', config.chunking ? 'true' : 'false')
    searchParams.set('chunk_size', config.chunkSize.toString())
    searchParams.set('chunk_divs', config.chunkDivs ? 'true' : 'false')
    searchParams.set('chunk_outlines', config.chunkOutlines ? 'true' : 'false')
    searchParams.set('content_visibility', config.contentVisibilityMode)
    searchParams.set(
      'selected_headings',
      config.showSelectedHeadings ? 'true' : 'false'
    )
    history.replaceState({}, '', `?${searchParams.toString()}`)
  }
}
const cachedInitialValue = []
const getInitialValue = blocks => {
  if (cachedInitialValue.length >= blocks) {
    return cachedInitialValue.slice(0, blocks)
  }
  faker.seed(1)
  for (let i = cachedInitialValue.length; i < blocks; i++) {
    if (i % 100 === 0) {
      const heading = {
        type: 'heading-one',

Review comment (suggestion):
Adds a checkbox to the huge document example to enable strict mode for testing. Due to the nature of strict mode, this only works when running the examples locally.

<img width="736" height="353" alt="image" src="https://github.com/user-attachments/assets/a6d8254c-68e9-42f7-92ac-1147d2e90592" />

Code after:
    : new URLSearchParams(document.location.search)
const parseNumber = (key, defaultValue) =>
  parseInt(searchParams?.get(key) ?? '', 10) || defaultValue
const parseBoolean = (key, defaultValue) => {
  const value = searchParams?.get(key)
  if (value) return value === 'true'
  return defaultValue
}
const parseEnum = (key, options, defaultValue) => {
  const value = searchParams?.get(key)
  if (value && options.includes(value)) return value
  return defaultValue
}
const initialConfig = {
  blocks: parseNumber('blocks', 10000),
  chunking: parseBoolean('chunking', true),
  chunkSize: parseNumber('chunk_size', 1000),
  chunkDivs: parseBoolean('chunk_divs', true),
  chunkOutlines: parseBoolean('chunk_outlines', false),
  contentVisibilityMode: parseEnum(
    'content_visibility',
    ['none', 'element', 'chunk'],
    'chunk'
  ),
  showSelectedHeadings: parseBoolean('selected_headings', false),
  strictMode: parseBoolean('strict', false),
}
const setSearchParams = config => {
  if (searchParams) {
    searchParams.set('blocks', config.blocks.toString())
    searchParams.set('chunking', config.chunking ? 'true' : 'false')
    searchParams.set('chunk_size', config.chunkSize.toString())
    searchParams.set('chunk_divs', config.chunkDivs ? 'true' : 'false')
    searchParams.set('chunk_outlines', config.chunkOutlines ? 'true' : 'false')
    searchParams.set('content_visibility', config.contentVisibilityMode)
    searchParams.set(
      'selected_headings',
      config.showSelectedHeadings ? 'true' : 'false'
    )
    searchParams.set('strict', config.strictMode ? 'true' : 'false')
    history.replaceState({}, '', `?${searchParams.toString()}`)
  }
}
const cachedInitialValue = []
const getInitialValue = blocks => {
  if (cachedInitialValue.length >= blocks) {
    return cachedInitialValue.slice(0, blocks)
  }
  faker.seed(1)
  for (let i = cachedInitialValue.length; i < blocks; i++) {
    if (i % 100 === 0) {