@allxsmith/bestax-bulma 5.62.0 → 5.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/bestax.css +1 -1
  2. package/dist/bestax.css.map +1 -1
  3. package/dist/esm/components/EmptyState.js +2 -6
  4. package/dist/esm/components/EmptyState.js.map +1 -1
  5. package/dist/esm/components/Timeline.js +5 -9
  6. package/dist/esm/components/Timeline.js.map +1 -1
  7. package/dist/esm/components/TreeView.js +3 -7
  8. package/dist/esm/components/TreeView.js.map +1 -1
  9. package/dist/esm/elements/Buttons.js +2 -0
  10. package/dist/esm/elements/Buttons.js.map +1 -1
  11. package/dist/esm/elements/CopyButton.js +132 -0
  12. package/dist/esm/elements/CopyButton.js.map +1 -0
  13. package/dist/esm/elements/DescriptionList.js +1 -5
  14. package/dist/esm/elements/DescriptionList.js.map +1 -1
  15. package/dist/esm/elements/Stat.js +196 -0
  16. package/dist/esm/elements/Stat.js.map +1 -0
  17. package/dist/esm/elements/Stats.js +48 -0
  18. package/dist/esm/elements/Stats.js.map +1 -0
  19. package/dist/esm/elements/statContext.js +10 -0
  20. package/dist/esm/elements/statContext.js.map +1 -0
  21. package/dist/esm/form/Combobox.js +2 -1
  22. package/dist/esm/form/Combobox.js.map +1 -1
  23. package/dist/esm/helpers/checkIcon.js +20 -0
  24. package/dist/esm/helpers/checkIcon.js.map +1 -0
  25. package/dist/esm/helpers/isGiven.js +13 -0
  26. package/dist/esm/helpers/isGiven.js.map +1 -0
  27. package/dist/esm/helpers/statusRegion.js +3 -3
  28. package/dist/esm/helpers/useClipboard.js +176 -0
  29. package/dist/esm/helpers/useClipboard.js.map +1 -0
  30. package/dist/extras.css +1 -1
  31. package/dist/extras.css.map +1 -1
  32. package/dist/index.cjs +4946 -4428
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.esm.js +4 -0
  35. package/dist/index.esm.js.map +1 -1
  36. package/dist/types/elements/Buttons.d.ts +1 -0
  37. package/dist/types/elements/CopyButton.d.ts +105 -0
  38. package/dist/types/elements/Stat.d.ts +242 -0
  39. package/dist/types/elements/Stats.d.ts +40 -0
  40. package/dist/types/elements/statContext.d.ts +18 -0
  41. package/dist/types/helpers/checkIcon.d.ts +10 -0
  42. package/dist/types/helpers/isGiven.d.ts +7 -0
  43. package/dist/types/helpers/useClipboard.d.ts +65 -0
  44. package/dist/types/index.d.ts +5 -0
  45. package/dist/types-cjs/elements/Buttons.d.ts +1 -0
  46. package/dist/types-cjs/elements/CopyButton.d.ts +105 -0
  47. package/dist/types-cjs/elements/Stat.d.ts +242 -0
  48. package/dist/types-cjs/elements/Stats.d.ts +40 -0
  49. package/dist/types-cjs/elements/statContext.d.ts +18 -0
  50. package/dist/types-cjs/helpers/checkIcon.d.ts +10 -0
  51. package/dist/types-cjs/helpers/isGiven.d.ts +7 -0
  52. package/dist/types-cjs/helpers/useClipboard.d.ts +65 -0
  53. package/dist/types-cjs/index.d.ts +5 -0
  54. package/dist/versions/bestax-no-dark-mode.css +1 -1
  55. package/dist/versions/bestax-no-dark-mode.css.map +1 -1
  56. package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
  57. package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
  58. package/dist/versions/bestax-no-helpers.css +1 -1
  59. package/dist/versions/bestax-no-helpers.css.map +1 -1
  60. package/dist/versions/bestax-prefixed.css +1 -1
  61. package/dist/versions/bestax-prefixed.css.map +1 -1
  62. package/package.json +1 -1
  63. package/src/scss/elements/_index.scss +1 -0
  64. package/src/scss/elements/_stat.scss +153 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClipboard.js","sources":["../../../src/helpers/useClipboard.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { useLatestRef } from './useLatestRef';\n\n/** Options for useClipboard. */\nexport interface UseClipboardOptions {\n /**\n * How long `copied` stays `true` after a copy, in milliseconds. Another\n * copy restarts it. `0` turns the timer off, as Toast's `0` does, so\n * `copied` stays `true` until a later copy fails. A missing or `NaN` value\n * uses the default, a negative one ends it at once, and `Infinity`, or\n * anything longer than the longest delay `setTimeout` takes (2147483647 ms,\n * about 24.8 days), is that longest delay.\n * @defaultValue 2000\n */\n duration?: number;\n /**\n * Called with `true` after each copy that worked, a repeat included, and\n * with `false` when `duration` runs out or a later copy fails.\n */\n onCopiedChange?: (copied: boolean) => void;\n /**\n * Called when neither the Clipboard API nor the copy command could write,\n * with the Clipboard API's own error when it refused, or an `Error` saying\n * neither could.\n */\n onCopyError?: (error: Error) => void;\n}\n\n/** What useClipboard returns. */\nexport interface UseClipboardResult {\n /**\n * Writes `text` to the clipboard, and resolves `true` once it's written or\n * `false` when it couldn't be. It never rejects. Call it from a click or a\n * key press, with no `await` before it: browsers only allow a write\n * shortly after one. A call that a later one overtakes leaves `copied`,\n * `error` and the callbacks to the later one, and doesn't fall back to the\n * copy command once the later one has started.\n */\n copy: (text: string) => Promise<boolean>;\n /**\n * `true` for `duration` after a copy that worked, or, with a `duration` of\n * `0`, until a later copy fails.\n */\n copied: boolean;\n /** Why the last copy failed, or `null` after one that worked. */\n error: Error | null;\n}\n\n/** How long `copied` lasts when `duration` doesn't say, in ms. */\nconst defaultDuration = 2000;\n\n/**\n * The longest delay `setTimeout` takes, in ms. A longer one, `Infinity`\n * included, runs at once.\n */\nconst longestDelay = 2 ** 31 - 1;\n\n/**\n * `duration` as a delay `setTimeout` keeps, or `null` for no timer: `null`\n * for `0`, as on Toast, the default when it's missing or `NaN` (or a\n * JavaScript caller's `null`), `0` for a negative one, which ends `copied` at\n * once, and the longest delay for `Infinity` or anything longer.\n */\nconst delayOf = (duration: number | null | undefined) => {\n if (duration === 0) return null;\n return duration == null || Number.isNaN(duration)\n ? defaultDuration\n : Math.min(Math.max(duration, 0), longestDelay);\n};\n\n/** The error a copy reports when nothing could write and nothing said why. */\nconst cannotCopy =\n 'The Clipboard API is missing or refused, and the copy command copied nothing.';\n\n/**\n * Copies `text` the way browsers did before the Clipboard API: it runs the\n * `copy` command and puts the text on the `copy` event that command fires.\n * Success is the event having fired, not the command's return value, which\n * WebKit reports as `false` for a copy that happened.\n *\n * This is the library's only call to the deprecated `document.execCommand`,\n * so it can go when browsers drop it. Until then it's what writes on a page\n * without the Clipboard API, such as one served over plain `http://`.\n *\n * @param text - The text to copy.\n * @returns Whether the `copy` event fired and took the text.\n */\nfunction copyWithCommand(text: string): boolean {\n let written = false;\n // WebKit enables the copy command only when something is selected or a\n // `beforecopy` listener cancels that event, and nothing is selected here.\n const enable = (event: Event) => event.preventDefault();\n // On `window` while capturing, so it runs before the page's listeners on\n // the document and its elements. The copy is this hook's own, so it's\n // stopped there: a page's own copy handler, such as one that adds a\n // credit line to whatever is copied, never sees it to rewrite it.\n const onCopy = (event: ClipboardEvent) => {\n if (!event.clipboardData) return;\n event.clipboardData.setData('text/plain', text);\n event.preventDefault();\n event.stopImmediatePropagation();\n written = true;\n };\n window.addEventListener('beforecopy', enable, true);\n window.addEventListener('copy', onCopy, true);\n try {\n document.execCommand('copy');\n } catch {\n // An engine that refuses, or no longer has the command, can throw, and\n // the event not firing already says so.\n } finally {\n window.removeEventListener('beforecopy', enable, true);\n window.removeEventListener('copy', onCopy, true);\n }\n return written;\n}\n\n/**\n * Writes `text` through the Clipboard API, and through the copy command when\n * that's missing or refuses. Where it's missing, the copy command runs before\n * the first `await`, so it's still inside the click that called it. After a\n * refusal it runs once the refusal arrives, which writes only where the\n * browser still counts the click by then, and only if no later copy has\n * started in the meantime, which it would otherwise write over.\n *\n * @param text - The text to write.\n * @param isLatest - Whether this is still the latest copy.\n * @returns `null` once it's written, or why it couldn't be.\n */\nasync function writeToClipboard(\n text: string,\n isLatest: () => boolean\n): Promise<Error | null> {\n let refusal: unknown = null;\n // Read at the click, never while rendering, so there's always a navigator.\n const { clipboard } = navigator;\n if (clipboard?.writeText) {\n try {\n await clipboard.writeText(text);\n return null;\n } catch (reason) {\n refusal = reason;\n }\n }\n if (isLatest() && copyWithCommand(text)) return null;\n return refusal instanceof Error ? refusal : new Error(cannotCopy);\n}\n\n/**\n * Copies text to the clipboard through the Clipboard API, falling back to the copy command where that's missing or refused, and keeps a `copied` flag for `duration` after a copy.\n *\n * It announces nothing. A trigger of your own says \"Copied\" in a\n * `role=\"status\"` region that's in the page before the click; `CopyButton`\n * is this hook with the button, the label and the announcement built in.\n *\n * A failed copy sets `error`, calls `onCopyError`, and ends `copied` if a\n * copy before it had set it. When copies overlap, only the latest one's\n * outcome sets the state and fires the callbacks, whichever finishes first.\n * Nothing changes and no callback fires once the component using it has\n * unmounted, though a write already under way still finishes.\n *\n * @function useClipboard\n * @param options - How long `copied` lasts, and the callbacks.\n * @returns `copy`, which writes, and the `copied` and `error` state.\n *\n * @example\n * const { copy, copied } = useClipboard();\n * <Button onClick={() => copy(url)}>{copied ? 'Copied' : 'Copy link'}</Button>\n */\nexport function useClipboard(\n options: UseClipboardOptions = {}\n): UseClipboardResult {\n const [copied, setCopied] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const optionsRef = useLatestRef(options);\n const copiedRef = useRef(false);\n const timerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const mountedRef = useRef(false);\n // Counts the calls to `copy`, so only the latest one's outcome is kept.\n const latestCallRef = useRef(0);\n\n useEffect(() => {\n mountedRef.current = true;\n return () => {\n mountedRef.current = false;\n clearTimeout(timerRef.current);\n };\n }, []);\n\n const copy = useCallback(\n async (text: string) => {\n latestCallRef.current += 1;\n const call = latestCallRef.current;\n const isLatest = () => call === latestCallRef.current;\n const failure = await writeToClipboard(text, isLatest);\n // A write overtaken by a later copy, which may finish first, reports\n // through its promise only.\n if (!mountedRef.current || !isLatest()) {\n return failure === null;\n }\n clearTimeout(timerRef.current);\n const { duration, onCopiedChange, onCopyError } = optionsRef.current;\n const wasCopied = copiedRef.current;\n copiedRef.current = failure === null;\n setCopied(failure === null);\n setError(failure);\n if (failure) {\n if (wasCopied) onCopiedChange?.(false);\n onCopyError?.(failure);\n return false;\n }\n onCopiedChange?.(true);\n const delay = delayOf(duration);\n if (delay !== null) {\n timerRef.current = setTimeout(() => {\n copiedRef.current = false;\n setCopied(false);\n optionsRef.current.onCopiedChange?.(false);\n }, delay);\n }\n return true;\n },\n [optionsRef]\n );\n\n return { copy, copied, error };\n}\n"],"names":[],"mappings":";;;;;AAgDA;AACA,MAAM,eAAe,GAAG,IAAI;AAE5B;;;AAGG;AACH,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;AAEhC;;;;;AAKG;AACH,MAAM,OAAO,GAAG,CAAC,QAAmC,KAAI;IACtD,IAAI,QAAQ,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;IAC/B,OAAO,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ;AAC9C,UAAE;AACF,UAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC;AACnD,CAAC;AAED;AACA,MAAM,UAAU,GACd,+EAA+E;AAEjF;;;;;;;;;;;;AAYG;AACH,SAAS,eAAe,CAAC,IAAY,EAAA;IACnC,IAAI,OAAO,GAAG,KAAK;;;IAGnB,MAAM,MAAM,GAAG,CAAC,KAAY,KAAK,KAAK,CAAC,cAAc,EAAE;;;;;AAKvD,IAAA,MAAM,MAAM,GAAG,CAAC,KAAqB,KAAI;QACvC,IAAI,CAAC,KAAK,CAAC,aAAa;YAAE;QAC1B,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC;QAC/C,KAAK,CAAC,cAAc,EAAE;QACtB,KAAK,CAAC,wBAAwB,EAAE;QAChC,OAAO,GAAG,IAAI;AAChB,IAAA,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC;IACnD,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC;AA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