@jbpark/live-editor 4.1.1 → 4.2.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 (50) hide show
  1. package/README.ko.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/{ast-jab6hQrT.js → ast-CMD20ykx.js} +94 -25
  4. package/dist/ast-CMD20ykx.js.map +1 -0
  5. package/dist/{compile-CBOAtQMz.js → compile-0Dvp8zp5.js} +37 -5
  6. package/dist/compile-0Dvp8zp5.js.map +1 -0
  7. package/dist/{constants-BD3FZKWE.js → constants-CKvdqZtO.js} +11 -4
  8. package/dist/constants-CKvdqZtO.js.map +1 -0
  9. package/dist/{context-DQ-UtoyS.js → context-93X3gyfJ.js} +2 -2
  10. package/dist/{context-DQ-UtoyS.js.map → context-93X3gyfJ.js.map} +1 -1
  11. package/dist/{core-DaXVtvH5.js → core-B3ruccKb.js} +2 -2
  12. package/dist/{core-DaXVtvH5.js.map → core-B3ruccKb.js.map} +1 -1
  13. package/dist/{detect-typescript-b0A751v2.js → detect-typescript-5MV4mCM7.js} +2 -2
  14. package/dist/{detect-typescript-b0A751v2.js.map → detect-typescript-5MV4mCM7.js.map} +1 -1
  15. package/dist/dnd/index.d.ts +2 -2
  16. package/dist/dnd/index.js +2 -2
  17. package/dist/{dnd-CMrXfD8O.js → dnd-DBaH2L8N.js} +545 -138
  18. package/dist/dnd-DBaH2L8N.js.map +1 -0
  19. package/dist/{document-C5Dypv4_.js → document-C3eCRQlj.js} +71 -38
  20. package/dist/document-C3eCRQlj.js.map +1 -0
  21. package/dist/{document-J9Lo9p81.d.ts → document-Ct4jW78J.d.ts} +42 -22
  22. package/dist/editor/index.js +2 -2
  23. package/dist/{editor-C3tQaMlU.js → editor-DvMruljw.js} +2 -2
  24. package/dist/{editor-C3tQaMlU.js.map → editor-DvMruljw.js.map} +1 -1
  25. package/dist/{index-C4t0OawE.d.ts → index-DVgwXnPa.d.ts} +109 -34
  26. package/dist/{index-B_p74BRM.d.ts → index-w3kLcCXl.d.ts} +29 -5
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +4 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/preview/index.js +2 -2
  31. package/dist/{preview-BwEfltgi.js → preview-B9Jhv1Up.js} +2 -2
  32. package/dist/{preview-BwEfltgi.js.map → preview-B9Jhv1Up.js.map} +1 -1
  33. package/dist/provider/index.js +1 -1
  34. package/dist/sections-A4TAXUP8.js +24 -0
  35. package/dist/sections-A4TAXUP8.js.map +1 -0
  36. package/dist/{use-dynamic-tailwind-DuGLeDR3.js → use-dynamic-tailwind-BDfytfYC.js} +16 -7
  37. package/dist/use-dynamic-tailwind-BDfytfYC.js.map +1 -0
  38. package/dist/utils/ast/index.d.ts +3 -3
  39. package/dist/utils/ast/index.js +3 -3
  40. package/dist/utils/index.d.ts +7 -6
  41. package/dist/utils/index.js +5 -5
  42. package/package.json +1 -1
  43. package/dist/ast-jab6hQrT.js.map +0 -1
  44. package/dist/compile-CBOAtQMz.js.map +0 -1
  45. package/dist/constants-BD3FZKWE.js.map +0 -1
  46. package/dist/dnd-CMrXfD8O.js.map +0 -1
  47. package/dist/document-C5Dypv4_.js.map +0 -1
  48. package/dist/sections-B7dWoNVJ.js +0 -19
  49. package/dist/sections-B7dWoNVJ.js.map +0 -1
  50. package/dist/use-dynamic-tailwind-DuGLeDR3.js.map +0 -1
@@ -1,16 +1,3 @@
1
- //#region src/types/index.d.ts
2
- interface Module {
3
- exports: {
4
- default?: React.ComponentType<Record<string, unknown>>;
5
- };
6
- error?: string;
7
- }
8
- interface Section {
9
- id: string;
10
- name: string;
11
- code: string;
12
- }
13
- //#endregion
14
1
  //#region node_modules/.pnpm/@babel+types@7.29.8/node_modules/@babel/types/lib/index-legacy.d.ts
15
2
  // NOTE: This file is autogenerated. Do not modify.
16
3
  // See packages/babel-types/scripts/generators/typescript-legacy.ts for script used.
@@ -1507,27 +1494,60 @@ type TSType = TSAnyKeyword | TSBooleanKeyword | TSBigIntKeyword | TSIntrinsicKey
1507
1494
  type TSBaseType = TSAnyKeyword | TSBooleanKeyword | TSBigIntKeyword | TSIntrinsicKeyword | TSNeverKeyword | TSNullKeyword | TSNumberKeyword | TSObjectKeyword | TSStringKeyword | TSSymbolKeyword | TSUndefinedKeyword | TSUnknownKeyword | TSVoidKeyword | TSThisType | TSTemplateLiteralType | TSLiteralType;
1508
1495
  type ModuleDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration;
1509
1496
  //#endregion
1497
+ //#region src/types/index.d.ts
1498
+ interface Module {
1499
+ exports: {
1500
+ default?: React.ComponentType<Record<string, unknown>>;
1501
+ };
1502
+ error?: string;
1503
+ }
1504
+ interface Section {
1505
+ id: string;
1506
+ name: string;
1507
+ code: string;
1508
+ }
1509
+ //#endregion
1510
1510
  //#region src/utils/ast/document.d.ts
1511
+ interface DocumentOptions {
1512
+ containerId?: string;
1513
+ }
1514
+ interface SectionOptions extends DocumentOptions {
1515
+ sectionNameFallback?: (index: number) => string;
1516
+ }
1517
+ type DocumentProblem = {
1518
+ reason: 'parse-error';
1519
+ error: unknown;
1520
+ } | {
1521
+ reason: 'container-not-found';
1522
+ containerId: string;
1523
+ };
1524
+ type DocumentInspection = {
1525
+ ok: true;
1526
+ doc: DocumentTree;
1527
+ } | ({
1528
+ ok: false;
1529
+ } & DocumentProblem);
1511
1530
  interface DocumentTree {
1512
1531
  code: string;
1513
1532
  ast: File;
1514
1533
  container: JSXElement;
1515
1534
  }
1516
- declare const parseDocument: (code: string) => DocumentTree | undefined;
1535
+ declare const inspectDocument: (code: string, { containerId }?: DocumentOptions) => DocumentInspection;
1536
+ declare const parseDocument: (code: string, options?: DocumentOptions) => DocumentTree | undefined;
1517
1537
  declare const clearDocumentParseCache: () => void;
1518
- declare const getSections: (doc: DocumentTree) => Section[];
1519
- declare const fillSectionIds: (code: string, generateId?: () => string) => string;
1538
+ declare const getSections: (doc: DocumentTree, { sectionNameFallback }?: SectionOptions) => Section[];
1539
+ declare const fillSectionIds: (code: string, generateId?: () => string, options?: DocumentOptions) => string;
1520
1540
  declare const generateDocumentCode: (doc: DocumentTree) => string;
1521
- declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[]) => string;
1522
- declare const generateSectionPreview: (fullCode: string, sectionCode: string) => string;
1523
- declare const generateSectionPreviews: (fullCode: string, sectionCodes: string[]) => string[];
1541
+ declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[], options?: DocumentOptions) => string;
1542
+ declare const generateSectionPreview: (fullCode: string, sectionCode: string, options?: DocumentOptions) => string;
1543
+ declare const generateSectionPreviews: (fullCode: string, sectionCodes: string[], options?: DocumentOptions) => string[];
1524
1544
  interface SectionPreviewCache {
1525
1545
  compute: (fullCode: string, sections: {
1526
1546
  id: string;
1527
1547
  code: string;
1528
- }[]) => string[];
1548
+ }[], options?: DocumentOptions) => string[];
1529
1549
  }
1530
1550
  declare const createSectionPreviewCache: () => SectionPreviewCache;
1531
1551
  //#endregion
1532
- export { Module as _, fillSectionIds as a, generateSectionPreviews as c, replaceDocumentSections as d, ArrayExpression as f, ObjectExpression as g, Node as h, createSectionPreviewCache as i, getSections as l, File as m, SectionPreviewCache as n, generateDocumentCode as o, Expression as p, clearDocumentParseCache as r, generateSectionPreview as s, DocumentTree as t, parseDocument as u, Section as v };
1533
- //# sourceMappingURL=document-J9Lo9p81.d.ts.map
1552
+ export { ObjectExpression as C, Node as S, Module as _, SectionOptions as a, Expression as b, createSectionPreviewCache as c, generateSectionPreview as d, generateSectionPreviews as f, replaceDocumentSections as g, parseDocument as h, DocumentTree as i, fillSectionIds as l, inspectDocument as m, DocumentOptions as n, SectionPreviewCache as o, getSections as p, DocumentProblem as r, clearDocumentParseCache as s, DocumentInspection as t, generateDocumentCode as u, Section as v, File as x, ArrayExpression as y };
1553
+ //# sourceMappingURL=document-Ct4jW78J.d.ts.map
@@ -1,3 +1,3 @@
1
- import { t as Core } from "../core-DaXVtvH5.js";
2
- import { t as Editor } from "../editor-C3tQaMlU.js";
1
+ import { t as Core } from "../core-B3ruccKb.js";
2
+ import { t as Editor } from "../editor-DvMruljw.js";
3
3
  export { Core, Editor as default };
@@ -1,5 +1,5 @@
1
1
  import { i as usePreview, r as useError } from "./states-Ci1AvoQ9.js";
2
- import { n as useFormatCode, t as Core } from "./core-DaXVtvH5.js";
2
+ import { n as useFormatCode, t as Core } from "./core-B3ruccKb.js";
3
3
  import { useCallback, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { useDebouncedCallback } from "@jbpark/use-hooks";
@@ -63,4 +63,4 @@ Editor.Core = Core;
63
63
  //#endregion
64
64
  export { Editor as t };
65
65
 
66
- //# sourceMappingURL=editor-C3tQaMlU.js.map
66
+ //# sourceMappingURL=editor-DvMruljw.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor-C3tQaMlU.js","names":["Editor","EditorImpl"],"sources":["../src/components/editor/editor.tsx","../src/components/editor/index.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\nimport { useDebouncedCallback } from '@jbpark/use-hooks';\n\nimport { useError, usePreview } from '~/components/context/states';\n\nimport Core, { type Props as CoreProps } from './core';\nimport { useFormatCode } from './use-format-code';\n\nexport interface EditorRenderData {\n value: string;\n onChange: (value: string) => void;\n // Same prettier-based formatting Core's own Cmd+S uses - reused rather\n // than reimplemented, so a custom editor can offer equivalent\n // format-on-save behavior without duplicating the prettier wiring.\n formatCode: (code: string) => Promise<string>;\n}\n\nexport interface Props extends Omit<CoreProps, 'value' | 'onSave' | 'onError'> {\n value?: string;\n defaultValue?: string;\n debounce?: number;\n // Full replacement for the built-in CodeMirror editor. Editor still owns\n // syncing `value` to the shared preview code (debounced), regardless of\n // which UI renders it - only the editing surface itself is customizable.\n renderEditor?: (data: EditorRenderData) => React.ReactNode;\n}\n\nconst Editor = ({\n defaultValue,\n value: _value,\n debounce = 1000,\n onChange: _onChange,\n renderEditor,\n fragment,\n prettierOptions,\n ...props\n}: Props) => {\n const { code, setCode } = usePreview();\n const { setError } = useError();\n\n // Controlled, the host owns the document. Uncontrolled, the provider does\n // (#341): `draft` shows each keystroke at once, while the provider only\n // hears about it after `debounce`. Without a draft, the editor had nowhere\n // to keep what was typed, so an uncontrolled editor dropped every edit.\n const controlled = _value !== undefined;\n const [draft, setDraft] = useState(() => defaultValue ?? code);\n\n // The last code this editor pushed, and the provider code it has already\n // seen. A provider change that isn't this editor's own push came from\n // somewhere else sharing the provider — an uncontrolled DnD, say — and the\n // draft follows it. Adjusted during render so no frame shows the old one.\n const [pushed, setPushed] = useState<string | null>(null);\n const [seenCode, setSeenCode] = useState(code);\n\n if (code !== seenCode) {\n setSeenCode(code);\n\n if (!controlled && code !== pushed) {\n setDraft(code);\n }\n }\n\n const value = controlled ? _value : draft;\n\n const pushCode = useCallback(\n (next: string) => {\n setPushed(next);\n setCode(next);\n },\n [setCode],\n );\n\n const onChange = useCallback(\n (next: string) => {\n if (!controlled) {\n setDraft(next);\n }\n\n _onChange?.(next);\n },\n [_onChange, controlled],\n );\n\n // Formatting on save reaches the provider at once, ahead of the debounce.\n const onSave = useCallback(\n (formattedCode: string) => {\n pushCode(formattedCode);\n },\n [pushCode],\n );\n\n const onError = useCallback(\n (error: string | null) => {\n setError(error);\n },\n [setError],\n );\n\n const formatCode = useFormatCode({ fragment, prettierOptions });\n\n // Pushes `value` to the provider `debounce` ms after it stops changing,\n // and at once on mount. A pending push is never dropped: it runs when the\n // editor unmounts, and when focus leaves it — so clicking into another\n // surface right after typing edits a document that includes the typing.\n const push = useDebouncedCallback(\n () => pushCode(value),\n { delay: debounce, flushOnUnmount: true },\n [value],\n );\n\n // `display: contents` so the wrapper adds a blur listener without adding a\n // box: the editor lays out against this element's parent, as before.\n return (\n <div style={{ display: 'contents' }} onBlur={push.flush}>\n {renderEditor ? (\n renderEditor({ value, onChange, formatCode })\n ) : (\n <Core\n value={value}\n onChange={onChange}\n onSave={onSave}\n onError={onError}\n fragment={fragment}\n prettierOptions={prettierOptions}\n {...props}\n />\n )}\n </div>\n );\n};\n\nexport default Editor;\n","import Core, { type Props as CoreProps } from './core';\nimport EditorImpl, { type EditorRenderData, type Props } from './editor';\n\ntype EditorComponent = typeof EditorImpl & { Core: typeof Core };\n\nconst Editor = EditorImpl as EditorComponent;\n\nEditor.Core = Core;\n\nexport { Core };\nexport type { Props, CoreProps, EditorRenderData };\nexport default Editor;\n"],"mappings":";;;;;;AA4BA,MAAMA,YAAU,EACd,cACA,OAAO,QACP,WAAW,KACX,UAAU,WACV,cACA,UACA,iBACA,GAAG,YACQ;CACX,MAAM,EAAE,MAAM,YAAY,WAAW;CACrC,MAAM,EAAE,aAAa,SAAS;CAM9B,MAAM,aAAa,WAAW,KAAA;CAC9B,MAAM,CAAC,OAAO,YAAY,eAAe,gBAAgB,IAAI;CAM7D,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,CAAC,UAAU,eAAe,SAAS,IAAI;CAE7C,IAAI,SAAS,UAAU;EACrB,YAAY,IAAI;EAEhB,IAAI,CAAC,cAAc,SAAS,QAC1B,SAAS,IAAI;CAEjB;CAEA,MAAM,QAAQ,aAAa,SAAS;CAEpC,MAAM,WAAW,aACd,SAAiB;EAChB,UAAU,IAAI;EACd,QAAQ,IAAI;CACd,GACA,CAAC,OAAO,CACV;CAEA,MAAM,WAAW,aACd,SAAiB;EAChB,IAAI,CAAC,YACH,SAAS,IAAI;EAGf,YAAY,IAAI;CAClB,GACA,CAAC,WAAW,UAAU,CACxB;CAGA,MAAM,SAAS,aACZ,kBAA0B;EACzB,SAAS,aAAa;CACxB,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,UAAU,aACb,UAAyB;EACxB,SAAS,KAAK;CAChB,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,aAAa,cAAc;EAAE;EAAU;CAAgB,CAAC;CAM9D,MAAM,OAAO,2BACL,SAAS,KAAK,GACpB;EAAE,OAAO;EAAU,gBAAgB;CAAK,GACxC,CAAC,KAAK,CACR;CAIA,OACE,oBAAC,OAAD;EAAK,OAAO,EAAE,SAAS,WAAW;EAAG,QAAQ,KAAK;EAC/C,UAAA,eACC,aAAa;GAAE;GAAO;GAAU;EAAW,CAAC,IAE5C,oBAAC,MAAD;GACS;GACG;GACF;GACC;GACC;GACO;GACjB,GAAI;EACL,CAAA;CAEA,CAAA;AAET;;;AC7HA,MAAM,SAASC;AAEf,OAAO,OAAO"}
1
+ {"version":3,"file":"editor-DvMruljw.js","names":["Editor","EditorImpl"],"sources":["../src/components/editor/editor.tsx","../src/components/editor/index.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\nimport { useDebouncedCallback } from '@jbpark/use-hooks';\n\nimport { useError, usePreview } from '~/components/context/states';\n\nimport Core, { type Props as CoreProps } from './core';\nimport { useFormatCode } from './use-format-code';\n\nexport interface EditorRenderData {\n value: string;\n onChange: (value: string) => void;\n // Same prettier-based formatting Core's own Cmd+S uses - reused rather\n // than reimplemented, so a custom editor can offer equivalent\n // format-on-save behavior without duplicating the prettier wiring.\n formatCode: (code: string) => Promise<string>;\n}\n\nexport interface Props extends Omit<CoreProps, 'value' | 'onSave' | 'onError'> {\n value?: string;\n defaultValue?: string;\n debounce?: number;\n // Full replacement for the built-in CodeMirror editor. Editor still owns\n // syncing `value` to the shared preview code (debounced), regardless of\n // which UI renders it - only the editing surface itself is customizable.\n renderEditor?: (data: EditorRenderData) => React.ReactNode;\n}\n\nconst Editor = ({\n defaultValue,\n value: _value,\n debounce = 1000,\n onChange: _onChange,\n renderEditor,\n fragment,\n prettierOptions,\n ...props\n}: Props) => {\n const { code, setCode } = usePreview();\n const { setError } = useError();\n\n // Controlled, the host owns the document. Uncontrolled, the provider does\n // (#341): `draft` shows each keystroke at once, while the provider only\n // hears about it after `debounce`. Without a draft, the editor had nowhere\n // to keep what was typed, so an uncontrolled editor dropped every edit.\n const controlled = _value !== undefined;\n const [draft, setDraft] = useState(() => defaultValue ?? code);\n\n // The last code this editor pushed, and the provider code it has already\n // seen. A provider change that isn't this editor's own push came from\n // somewhere else sharing the provider — an uncontrolled DnD, say — and the\n // draft follows it. Adjusted during render so no frame shows the old one.\n const [pushed, setPushed] = useState<string | null>(null);\n const [seenCode, setSeenCode] = useState(code);\n\n if (code !== seenCode) {\n setSeenCode(code);\n\n if (!controlled && code !== pushed) {\n setDraft(code);\n }\n }\n\n const value = controlled ? _value : draft;\n\n const pushCode = useCallback(\n (next: string) => {\n setPushed(next);\n setCode(next);\n },\n [setCode],\n );\n\n const onChange = useCallback(\n (next: string) => {\n if (!controlled) {\n setDraft(next);\n }\n\n _onChange?.(next);\n },\n [_onChange, controlled],\n );\n\n // Formatting on save reaches the provider at once, ahead of the debounce.\n const onSave = useCallback(\n (formattedCode: string) => {\n pushCode(formattedCode);\n },\n [pushCode],\n );\n\n const onError = useCallback(\n (error: string | null) => {\n setError(error);\n },\n [setError],\n );\n\n const formatCode = useFormatCode({ fragment, prettierOptions });\n\n // Pushes `value` to the provider `debounce` ms after it stops changing,\n // and at once on mount. A pending push is never dropped: it runs when the\n // editor unmounts, and when focus leaves it — so clicking into another\n // surface right after typing edits a document that includes the typing.\n const push = useDebouncedCallback(\n () => pushCode(value),\n { delay: debounce, flushOnUnmount: true },\n [value],\n );\n\n // `display: contents` so the wrapper adds a blur listener without adding a\n // box: the editor lays out against this element's parent, as before.\n return (\n <div style={{ display: 'contents' }} onBlur={push.flush}>\n {renderEditor ? (\n renderEditor({ value, onChange, formatCode })\n ) : (\n <Core\n value={value}\n onChange={onChange}\n onSave={onSave}\n onError={onError}\n fragment={fragment}\n prettierOptions={prettierOptions}\n {...props}\n />\n )}\n </div>\n );\n};\n\nexport default Editor;\n","import Core, { type Props as CoreProps } from './core';\nimport EditorImpl, { type EditorRenderData, type Props } from './editor';\n\ntype EditorComponent = typeof EditorImpl & { Core: typeof Core };\n\nconst Editor = EditorImpl as EditorComponent;\n\nEditor.Core = Core;\n\nexport { Core };\nexport type { Props, CoreProps, EditorRenderData };\nexport default Editor;\n"],"mappings":";;;;;;AA4BA,MAAMA,YAAU,EACd,cACA,OAAO,QACP,WAAW,KACX,UAAU,WACV,cACA,UACA,iBACA,GAAG,YACQ;CACX,MAAM,EAAE,MAAM,YAAY,WAAW;CACrC,MAAM,EAAE,aAAa,SAAS;CAM9B,MAAM,aAAa,WAAW,KAAA;CAC9B,MAAM,CAAC,OAAO,YAAY,eAAe,gBAAgB,IAAI;CAM7D,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,CAAC,UAAU,eAAe,SAAS,IAAI;CAE7C,IAAI,SAAS,UAAU;EACrB,YAAY,IAAI;EAEhB,IAAI,CAAC,cAAc,SAAS,QAC1B,SAAS,IAAI;CAEjB;CAEA,MAAM,QAAQ,aAAa,SAAS;CAEpC,MAAM,WAAW,aACd,SAAiB;EAChB,UAAU,IAAI;EACd,QAAQ,IAAI;CACd,GACA,CAAC,OAAO,CACV;CAEA,MAAM,WAAW,aACd,SAAiB;EAChB,IAAI,CAAC,YACH,SAAS,IAAI;EAGf,YAAY,IAAI;CAClB,GACA,CAAC,WAAW,UAAU,CACxB;CAGA,MAAM,SAAS,aACZ,kBAA0B;EACzB,SAAS,aAAa;CACxB,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,UAAU,aACb,UAAyB;EACxB,SAAS,KAAK;CAChB,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,aAAa,cAAc;EAAE;EAAU;CAAgB,CAAC;CAM9D,MAAM,OAAO,2BACL,SAAS,KAAK,GACpB;EAAE,OAAO;EAAU,gBAAgB;CAAK,GACxC,CAAC,KAAK,CACR;CAIA,OACE,oBAAC,OAAD;EAAK,OAAO,EAAE,SAAS,WAAW;EAAG,QAAQ,KAAK;EAC/C,UAAA,eACC,aAAa;GAAE;GAAO;GAAU;EAAW,CAAC,IAE5C,oBAAC,MAAD;GACS;GACG;GACF;GACC;GACC;GACO;GACjB,GAAI;EACL,CAAA;CAEA,CAAA;AAET;;;AC7HA,MAAM,SAASC;AAEf,OAAO,OAAO"}
@@ -1,6 +1,6 @@
1
- import { v as Section } from "./document-J9Lo9p81.js";
1
+ import { $ as BindingWidget, Q as BindingType, Y as BindingOption, Z as BindingRenderMap, et as DataAttrNode, f as UpdateFailure } from "./index-w3kLcCXl.js";
2
+ import { v as Section } from "./document-Ct4jW78J.js";
2
3
  import { t as FrameProps } from "./index-DpDU1IAw.js";
3
- import { J as BindingRenderMap, K as BindingOption, X as BindingWidget, Y as BindingType, Z as DataAttrNode, u as UpdateFailure } from "./index-B_p74BRM.js";
4
4
  import { useMultiSelect } from "@jbpark/use-hooks";
5
5
  //#region src/components/dnd/panel/field.d.ts
6
6
  interface FieldProps {
@@ -24,6 +24,20 @@ type DndEditError = {
24
24
  error?: unknown;
25
25
  title: string;
26
26
  description?: string;
27
+ } | {
28
+ type: 'parse';
29
+ target: 'document';
30
+ reason: 'parse-error';
31
+ error: unknown;
32
+ title: string;
33
+ description?: string;
34
+ } | {
35
+ type: 'parse';
36
+ target: 'document';
37
+ reason: 'container-not-found';
38
+ containerId: string;
39
+ title: string;
40
+ description?: string;
27
41
  } | {
28
42
  type: 'items';
29
43
  title: string;
@@ -40,6 +54,9 @@ interface PanelNodeChange {
40
54
  value: unknown;
41
55
  }): void;
42
56
  }
57
+ interface PanelNodesChange {
58
+ (changes: Parameters<PanelNodeChange>[0][]): void;
59
+ }
43
60
  interface PanelBinding {
44
61
  id: string;
45
62
  label: string;
@@ -56,8 +73,17 @@ interface PanelBinding {
56
73
  value: unknown;
57
74
  rawValue: string;
58
75
  canEditValue?: boolean;
76
+ present?: boolean;
59
77
  onChange: (value: unknown) => void;
60
78
  }
79
+ type PanelBindingData = Omit<PanelBinding, 'onChange'>;
80
+ interface PanelBindingSource {
81
+ id: string;
82
+ tagName: string;
83
+ bindings: PanelBindingData[];
84
+ }
85
+ declare const resolvePanelBindings: (node: DataAttrNode) => PanelBindingSource | null;
86
+ declare const withPanelCommit: (bindings: PanelBindingData[], commit: PanelNodeChange | undefined) => PanelBinding[];
61
87
  //#endregion
62
88
  //#region src/components/dnd/section-fallback-context.d.ts
63
89
  interface DndSectionFallbackArgs {
@@ -82,6 +108,8 @@ interface DndPanel {
82
108
  canMoveDown: boolean;
83
109
  bindings: PanelBinding[];
84
110
  onNodeChange: PanelNodeChange;
111
+ onNodesChange: PanelNodesChange;
112
+ readOnly: boolean;
85
113
  }
86
114
  interface Props extends Omit<React.ComponentPropsWithRef<'div'>, 'onChange'> {
87
115
  value?: string;
@@ -96,9 +124,12 @@ interface Props extends Omit<React.ComponentPropsWithRef<'div'>, 'onChange'> {
96
124
  onEditError?: (error: DndEditError) => void;
97
125
  renderSectionFallback?: DndRenderSectionFallback;
98
126
  shouldForceSectionFallback?: (section: Section) => boolean;
127
+ onBeforeDelete?: (section: Section) => boolean | Promise<boolean>;
128
+ sectionNameFallback?: (index: number) => string;
129
+ containerId?: string;
99
130
  children?: React.ReactNode;
100
131
  }
101
- declare const Dnd$1: ({ value: _value, props, modules: _modules, onChange: _onChange, className, items, frame, dynamicTailwind, provider, renderField, onEditError, renderSectionFallback, shouldForceSectionFallback, children, ...restProps }: Props) => import("react").JSX.Element;
132
+ declare const Dnd$1: ({ value: _value, props, modules: _modules, onChange: _onChange, className, items, frame, dynamicTailwind, provider, renderField, onEditError, renderSectionFallback, shouldForceSectionFallback, onBeforeDelete, sectionNameFallback, containerId, children, ...restProps }: Props) => import("react").JSX.Element;
102
133
  //#endregion
103
134
  //#region src/components/dnd/draggable.d.ts
104
135
  interface DraggableItemDragState {
@@ -130,31 +161,56 @@ interface DndLayout {
130
161
  clearSelection: () => void;
131
162
  paletteOpen: boolean;
132
163
  setPaletteOpen: (open: boolean) => void;
164
+ documentError: 'parse-error' | 'container-not-found' | null;
133
165
  }
134
166
  declare const useDndPalette: () => DndPalette;
135
167
  declare const useDndPanel: () => DndPanel;
136
168
  declare const useDndLayout: () => DndLayout;
137
169
  //#endregion
138
- //#region src/components/dnd/panel/use-items-editor.d.ts
139
- interface ItemsEditorNestedElement {
170
+ //#region src/components/dnd/panel/use-dnd-children.d.ts
171
+ interface DndChildrenOptions {
172
+ onChange?: (value: string) => void;
173
+ }
174
+ declare const useDndChildren: (items: DataAttrNode[], { onChange }?: DndChildrenOptions) => {
175
+ items: DataAttrNode[];
176
+ selection: {
177
+ readonly selected: Set<number>;
178
+ readonly isSelected: (index: number) => boolean;
179
+ readonly toggle: (index: number, shiftKey?: boolean) => void;
180
+ readonly clear: () => void;
181
+ readonly replace: (indices: Set<number>) => void;
182
+ };
183
+ actions: {
184
+ move: (from: number, to: number) => void;
185
+ remove: (index: number) => void;
186
+ add: () => void;
187
+ duplicateSelected: () => void;
188
+ moveSelected: (direction: "up" | "down") => void;
189
+ removeSelected: () => void;
190
+ };
191
+ };
192
+ type DndChildren = ReturnType<typeof useDndChildren>;
193
+ //#endregion
194
+ //#region src/components/dnd/panel/use-dnd-items.d.ts
195
+ interface DndItemsNestedElement {
140
196
  id: string;
141
197
  tagName: string;
142
198
  bindings: PanelBinding[];
143
199
  }
144
- interface ItemsEditorNestedGroup {
200
+ interface DndItemsNestedGroup {
145
201
  property: string;
146
- elements: ItemsEditorNestedElement[];
202
+ elements: DndItemsNestedElement[];
147
203
  fallback?: PanelBinding;
148
204
  }
149
- interface ItemsEditorItem {
205
+ interface DndItemsItem {
150
206
  id: string;
151
207
  index: number;
152
208
  elementIndex: number;
153
209
  properties: PanelBinding[];
154
- nested: ItemsEditorNestedGroup[];
210
+ nested: DndItemsNestedGroup[];
155
211
  value?: PanelBinding;
156
212
  }
157
- interface ItemsEditorActions {
213
+ interface DndItemsActions {
158
214
  add: () => void;
159
215
  move: (elementIndex: number, toIndex: number) => void;
160
216
  remove: (elementIndex: number) => void;
@@ -162,26 +218,41 @@ interface ItemsEditorActions {
162
218
  moveSelected: (direction: 'up' | 'down') => void;
163
219
  removeSelected: () => void;
164
220
  }
165
- interface ItemsEditor {
221
+ interface DndItems {
166
222
  kind: 'object' | 'primitive';
167
- items: ItemsEditorItem[];
223
+ items: DndItemsItem[];
168
224
  selection: ReturnType<typeof useMultiSelect>;
169
- actions: ItemsEditorActions;
225
+ actions: DndItemsActions;
170
226
  canEditStructure: boolean;
171
227
  parseError: boolean;
172
228
  }
173
- interface ItemsEditorOptions {
229
+ interface DndItemsOptions {
174
230
  render?: BindingRenderMap;
175
231
  onChange?: (value: string) => void;
176
232
  onNodeChange?: PanelNodeChange;
177
233
  }
178
- declare const useItemsEditor: (value: string, { render, onChange, onNodeChange }?: ItemsEditorOptions) => ItemsEditor;
234
+ declare const useDndItems: (value: string, { render, onChange, onNodeChange }?: DndItemsOptions) => DndItems;
179
235
  //#endregion
180
- //#region src/components/dnd/panel/use-children-editor.d.ts
181
- interface ChildrenEditorOptions {
182
- onChange?: (value: string) => void;
183
- }
184
- declare const useChildrenEditor: (items: DataAttrNode[], { onChange }?: ChildrenEditorOptions) => {
236
+ //#region src/components/dnd/panel/field-kind.d.ts
237
+ type FieldKind = 'readonly' | 'items' | 'children' | 'richtext' | 'jsx' | 'html' | 'object' | 'boolean' | 'select' | 'color' | 'date' | 'url' | 'number' | 'text';
238
+ type FieldKindBinding = Pick<PanelBinding, 'property' | 'type' | 'value' | 'options' | 'canEditValue'>;
239
+ declare const getFieldKind: (binding: FieldKindBinding) => FieldKind;
240
+ declare const isStructuralFieldKind: (kind: FieldKind) => kind is "items" | "children";
241
+ //#endregion
242
+ //#region src/components/dnd/index.d.ts
243
+ type DndComponent = typeof Dnd$1 & {
244
+ DraggableItem: typeof DraggableItem;
245
+ Field: typeof Field;
246
+ Palette: typeof Palette;
247
+ Canvas: typeof Canvas;
248
+ Panel: typeof Panel;
249
+ Layout: typeof Layout;
250
+ };
251
+ declare const Dnd: DndComponent;
252
+ /** @deprecated Renamed to `useDndItems`. */
253
+ declare const useItemsEditor: (value: string, { render, onChange, onNodeChange }?: DndItemsOptions) => DndItems;
254
+ /** @deprecated Renamed to `useDndChildren`. */
255
+ declare const useChildrenEditor: (items: DataAttrNode[], { onChange }?: DndChildrenOptions) => {
185
256
  items: DataAttrNode[];
186
257
  selection: {
187
258
  readonly selected: Set<number>;
@@ -199,18 +270,22 @@ declare const useChildrenEditor: (items: DataAttrNode[], { onChange }?: Children
199
270
  removeSelected: () => void;
200
271
  };
201
272
  };
202
- type ChildrenEditor = ReturnType<typeof useChildrenEditor>;
203
- //#endregion
204
- //#region src/components/dnd/index.d.ts
205
- type DndComponent = typeof Dnd$1 & {
206
- DraggableItem: typeof DraggableItem;
207
- Field: typeof Field;
208
- Palette: typeof Palette;
209
- Canvas: typeof Canvas;
210
- Panel: typeof Panel;
211
- Layout: typeof Layout;
212
- };
213
- declare const Dnd: DndComponent;
273
+ /** @deprecated Renamed to `DndItems`. */
274
+ type ItemsEditor = DndItems;
275
+ /** @deprecated Renamed to `DndItemsActions`. */
276
+ type ItemsEditorActions = DndItemsActions;
277
+ /** @deprecated Renamed to `DndItemsItem`. */
278
+ type ItemsEditorItem = DndItemsItem;
279
+ /** @deprecated Renamed to `DndItemsNestedElement`. */
280
+ type ItemsEditorNestedElement = DndItemsNestedElement;
281
+ /** @deprecated Renamed to `DndItemsNestedGroup`. */
282
+ type ItemsEditorNestedGroup = DndItemsNestedGroup;
283
+ /** @deprecated Renamed to `DndItemsOptions`. */
284
+ type ItemsEditorOptions = DndItemsOptions;
285
+ /** @deprecated Renamed to `DndChildren`. */
286
+ type ChildrenEditor = DndChildren;
287
+ /** @deprecated Renamed to `DndChildrenOptions`. */
288
+ type ChildrenEditorOptions = DndChildrenOptions;
214
289
  //#endregion
215
- export { PanelBinding as A, DraggableItemDragState as C, Props as D, DndPanel as E, FieldProps as F, DndEditError as M, DndRenderField as N, DndRenderSectionFallback as O, Field as P, DraggableItem as S, DndPalette as T, DndLayoutProps as _, ItemsEditor as a, Palette as b, ItemsEditorNestedElement as c, useItemsEditor as d, DndLayout as f, Canvas as g, useDndPanel as h, useChildrenEditor as i, PanelNodeChange as j, DndSectionFallbackArgs as k, ItemsEditorNestedGroup as l, useDndPalette as m, ChildrenEditor as n, ItemsEditorActions as o, useDndLayout as p, ChildrenEditorOptions as r, ItemsEditorItem as s, Dnd as t, ItemsEditorOptions as u, DndRegionProps as v, DraggableItemProps as w, Panel as x, Layout as y };
216
- //# sourceMappingURL=index-C4t0OawE.d.ts.map
290
+ export { Field as $, Canvas as A, DndPanel as B, DndChildren as C, useDndLayout as D, DndLayout as E, Panel as F, PanelBindingData as G, DndRenderSectionFallback as H, DraggableItem as I, PanelNodesChange as J, PanelBindingSource as K, DraggableItemDragState as L, DndRegionProps as M, Layout as N, useDndPalette as O, Palette as P, DndRenderField as Q, DraggableItemProps as R, useDndItems as S, useDndChildren as T, DndSectionFallbackArgs as U, Props as V, PanelBinding as W, withPanelCommit as X, resolvePanelBindings as Y, DndEditError as Z, DndItemsActions as _, ItemsEditorActions as a, DndItemsNestedGroup as b, ItemsEditorNestedGroup as c, useItemsEditor as d, FieldProps as et, FieldKind as f, DndItems as g, isStructuralFieldKind as h, ItemsEditor as i, DndLayoutProps as j, useDndPanel as k, ItemsEditorOptions as l, getFieldKind as m, ChildrenEditorOptions as n, ItemsEditorItem as o, FieldKindBinding as p, PanelNodeChange as q, Dnd as r, ItemsEditorNestedElement as s, ChildrenEditor as t, useChildrenEditor as u, DndItemsItem as v, DndChildrenOptions as w, DndItemsOptions as x, DndItemsNestedElement as y, DndPalette as z };
291
+ //# sourceMappingURL=index-DVgwXnPa.d.ts.map
@@ -1,4 +1,4 @@
1
- import { f as ArrayExpression, g as ObjectExpression, h as Node, m as File, p as Expression } from "./document-J9Lo9p81.js";
1
+ import { C as ObjectExpression, S as Node, b as Expression, x as File, y as ArrayExpression } from "./document-Ct4jW78J.js";
2
2
  //#region src/utils/ast/types.d.ts
3
3
  interface Attribute {
4
4
  name: string;
@@ -127,6 +127,14 @@ type UpdateFailure = {
127
127
  } | {
128
128
  reason: 'no-binding';
129
129
  dataId: string;
130
+ } | {
131
+ reason: 'reserved-property';
132
+ dataId: string;
133
+ property: string;
134
+ } | {
135
+ reason: 'required-property';
136
+ dataId: string;
137
+ property: string;
130
138
  } | {
131
139
  reason: 'binding-not-declared';
132
140
  dataId: string;
@@ -157,12 +165,28 @@ interface UpdateResult {
157
165
  failures?: UpdateFailure[];
158
166
  }
159
167
  declare const update: (code: string, dataId: string, label: string, value: unknown, property?: string) => UpdateResult;
160
- declare const bulkUpdate: (raw: string, entries: {
168
+ interface UpdateEntry {
161
169
  dataId: string;
162
170
  label: string;
163
171
  value: unknown;
164
172
  property?: string;
165
- }[]) => UpdateResult;
173
+ }
174
+ type UpdateAllResult = {
175
+ success: true;
176
+ code: string;
177
+ } | {
178
+ success: false;
179
+ code: string;
180
+ failure: UpdateFailure;
181
+ index: number;
182
+ };
183
+ declare const updateAll: (raw: string, entries: UpdateEntry[]) => UpdateAllResult;
184
+ /**
185
+ * @deprecated Not atomic: when an entry fails, the ones before and after it
186
+ * are still applied, and the returned `code` carries them. Use `updateAll`,
187
+ * which applies every entry or none. Will be removed in the next major.
188
+ */
189
+ declare const bulkUpdate: (raw: string, entries: UpdateEntry[]) => UpdateResult;
166
190
  //#endregion
167
191
  //#region src/utils/ast/children.d.ts
168
192
  type ChildrenAction = {
@@ -227,5 +251,5 @@ interface ValidationResult {
227
251
  }
228
252
  declare const validateBindingValue: (binding: BindingItem, value: unknown) => ValidationResult;
229
253
  //#endregion
230
- export { ExtractedNodeValue as $, arrayExpressionToCode as A, getCurrentValue as B, removeArrayItems as C, EditablePathSegment as D, generateCode as E, flattenEditableValue as F, BindingItem as G, parseBinding as H, parseArrayExpression as I, BindingRenderMap as J, BindingOption as K, parseValue as L, createNodeFromValue as M, extractNodeValue as N, EditablePrimitive as O, extractObjectProperties as P, EditableNodeValueType as Q, setEditableValue as R, parseItems as S, updateArrayItemValue as T, parseBindingExpression as U, getStructuredValue as V, BindingFieldSpec as W, BindingWidget as X, BindingType as Y, DataAttrNode as Z, ItemKind as _, replaceIds as a, moveArrayItem as b, ChildrenEdit as c, UpdateResult as d, NodeValueType as et, bulkUpdate as f, ArrayItem as g, extract as h, fillIds as i, canLosslesslyEvaluateSource as j, EditableValueEntry as k, getChildrenSignatures as l, clearExtractCache as m, validateBindingValue as n, canStructurallyEditArray as o, update as p, BindingRenderLeaf as q, clone as r, ChildrenAction as s, ValidationResult as t, UpdateFailure as u, appendArrayItem as v, updateArrayItemProperty as w, moveArrayItems as x, duplicateArrayItems as y, findEditableChildren as z };
231
- //# sourceMappingURL=index-B_p74BRM.d.ts.map
254
+ export { BindingWidget as $, EditablePathSegment as A, parseValue as B, moveArrayItem as C, updateArrayItemProperty as D, removeArrayItems as E, createNodeFromValue as F, parseBinding as G, findEditableChildren as H, extractNodeValue as I, BindingItem as J, parseBindingExpression as K, extractObjectProperties as L, EditableValueEntry as M, arrayExpressionToCode as N, updateArrayItemValue as O, canLosslesslyEvaluateSource as P, BindingType as Q, flattenEditableValue as R, duplicateArrayItems as S, parseItems as T, getCurrentValue as U, setEditableValue as V, getStructuredValue as W, BindingRenderLeaf as X, BindingOption as Y, BindingRenderMap as Z, clearExtractCache as _, replaceIds as a, ItemKind as b, ChildrenEdit as c, UpdateEntry as d, DataAttrNode as et, UpdateFailure as f, updateAll as g, update as h, fillIds as i, EditablePrimitive as j, generateCode as k, getChildrenSignatures as l, bulkUpdate as m, validateBindingValue as n, ExtractedNodeValue as nt, canStructurallyEditArray as o, UpdateResult as p, BindingFieldSpec as q, clone as r, NodeValueType as rt, ChildrenAction as s, ValidationResult as t, EditableNodeValueType as tt, UpdateAllResult as u, extract as v, moveArrayItems as w, appendArrayItem as x, ArrayItem as y, parseArrayExpression as z };
255
+ //# sourceMappingURL=index-w3kLcCXl.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { v as Section } from "./document-J9Lo9p81.js";
1
+ import { v as Section } from "./document-Ct4jW78J.js";
2
2
  import { t as FrameProps } from "./index-DpDU1IAw.js";
3
- import { A as PanelBinding, D as Props, E as DndPanel, F as FieldProps, M as DndEditError, N as DndRenderField, O as DndRenderSectionFallback, T as DndPalette, a as ItemsEditor, b as Palette, f as DndLayout, g as Canvas, j as PanelNodeChange, k as DndSectionFallbackArgs, s as ItemsEditorItem, t as Dnd, u as ItemsEditorOptions, w as DraggableItemProps, x as Panel, y as Layout } from "./index-C4t0OawE.js";
3
+ import { A as Canvas, B as DndPanel, E as DndLayout, F as Panel, H as DndRenderSectionFallback, J as PanelNodesChange, N as Layout, P as Palette, Q as DndRenderField, R as DraggableItemProps, U as DndSectionFallbackArgs, V as Props, W as PanelBinding, Z as DndEditError, et as FieldProps, g as DndItems, i as ItemsEditor, l as ItemsEditorOptions, o as ItemsEditorItem, q as PanelNodeChange, r as Dnd, v as DndItemsItem, x as DndItemsOptions, z as DndPalette } from "./index-DVgwXnPa.js";
4
4
  import { a as Props$2, n as EditorRenderData, r as Props$1, t as Editor } from "./index-13BDSrQc.js";
5
5
  import { a as Props$5, n as Props$4, o as Props$3, s as ErrorBoundary, t as Error } from "./index-DNNj_0ba.js";
6
6
  import { n as Preview, r as Props$6 } from "./index-DQkL37eL.js";
@@ -19,7 +19,7 @@ declare const App: {
19
19
  Editor: (({ defaultValue, value: _value, debounce, onChange: _onChange, renderEditor, fragment, prettierOptions, ...props }: Props$1) => import("react").JSX.Element) & {
20
20
  Core: ({ value, theme, height, className, prettierOptions, fragment, raw, onChange, onSave, onError, ...props }: Props$2) => import("react").JSX.Element;
21
21
  };
22
- Dnd: (({ value: _value, props, modules: _modules, onChange: _onChange, className, items, frame, dynamicTailwind, provider, renderField, onEditError, renderSectionFallback, shouldForceSectionFallback, children, ...restProps }: Props) => import("react").JSX.Element) & {
22
+ Dnd: (({ value: _value, props, modules: _modules, onChange: _onChange, className, items, frame, dynamicTailwind, provider, renderField, onEditError, renderSectionFallback, shouldForceSectionFallback, onBeforeDelete, sectionNameFallback, containerId, children, ...restProps }: Props) => import("react").JSX.Element) & {
23
23
  DraggableItem: ({ item, children }: DraggableItemProps) => import("react").ReactNode;
24
24
  Field: (props: FieldProps) => import("react").JSX.Element;
25
25
  Palette: typeof Palette;
@@ -30,5 +30,5 @@ declare const App: {
30
30
  };
31
31
  declare const LiveRenderer: ({ code, props, modules, dynamicTailwind, provider, ...restProps }: Props$6) => import("react").JSX.Element;
32
32
  //#endregion
33
- export { type DndEditError, type DndLayout, type DndPalette, type DndPanel, type DndRenderField, type DndRenderSectionFallback, type DndSectionFallbackArgs, type EditorRenderData, type FieldProps, type FrameProps, type ItemsEditor, type ItemsEditorItem, type ItemsEditorOptions, Dnd as LiveDnd, Editor as LiveEditor, Error as LiveError, Preview as LivePreview, App as LiveProvider, App as default, LiveRenderer, type PanelBinding, type PanelNodeChange, type Section };
33
+ export { type DndEditError, type DndItems, type DndItemsItem, type DndItemsOptions, type DndLayout, type DndPalette, type DndPanel, type DndRenderField, type DndRenderSectionFallback, type DndSectionFallbackArgs, type EditorRenderData, type FieldProps, type FrameProps, type ItemsEditor, type ItemsEditorItem, type ItemsEditorOptions, Dnd as LiveDnd, Editor as LiveEditor, Error as LiveError, Preview as LivePreview, App as LiveProvider, App as default, LiveRenderer, type PanelBinding, type PanelNodeChange, type PanelNodesChange, type Section };
34
34
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as ContextProvider } from "./context-DQ-UtoyS.js";
2
- import { t as Dnd } from "./dnd-CMrXfD8O.js";
3
- import { t as Editor } from "./editor-C3tQaMlU.js";
1
+ import { t as ContextProvider } from "./context-93X3gyfJ.js";
2
+ import { t as Dnd } from "./dnd-DBaH2L8N.js";
3
+ import { t as Editor } from "./editor-DvMruljw.js";
4
4
  import { t as Error } from "./error-KW8XCcjH.js";
5
- import { t as Preview } from "./preview-BwEfltgi.js";
5
+ import { t as Preview } from "./preview-B9Jhv1Up.js";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  //#region src/index.tsx
8
8
  const App = ({ children }) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Context","LivePreview","LiveError","LiveEditor","LiveDnd"],"sources":["../src/index.tsx"],"sourcesContent":["import './index.css';\n\nimport Context from './components/context';\nimport LiveDnd, {\n type DndEditError,\n type DndLayout,\n type DndPalette,\n type DndPanel,\n type DndRenderField,\n type DndRenderSectionFallback,\n type DndSectionFallbackArgs,\n type FieldProps,\n type ItemsEditor,\n type ItemsEditorItem,\n type ItemsEditorOptions,\n type PanelBinding,\n type PanelNodeChange,\n} from './components/dnd';\nimport LiveEditor, { type EditorRenderData } from './components/editor';\nimport LiveError from './components/error';\nimport { type FrameProps } from './components/frame';\nimport LivePreview from './components/preview';\nimport type { Section } from './types';\n\nconst App = ({ children }: { children?: React.ReactNode }) => {\n return <Context>{children}</Context>;\n};\n\nconst LiveRenderer = LivePreview;\n\nexport {\n LivePreview,\n LiveError,\n LiveEditor,\n LiveDnd,\n LiveRenderer,\n App as LiveProvider,\n //\n};\n\nexport type {\n DndEditError,\n DndRenderField,\n DndRenderSectionFallback,\n DndSectionFallbackArgs,\n DndPalette,\n DndPanel,\n DndLayout,\n PanelBinding,\n PanelNodeChange,\n FieldProps,\n ItemsEditor,\n ItemsEditorItem,\n ItemsEditorOptions,\n EditorRenderData,\n FrameProps,\n Section,\n};\n\nApp.Preview = LivePreview;\nApp.Renderer = LiveRenderer;\nApp.Error = LiveError;\nApp.Editor = LiveEditor;\nApp.Dnd = LiveDnd;\n\nexport default App;\n"],"mappings":";;;;;;;AAwBA,MAAM,OAAO,EAAE,eAA+C;CAC5D,OAAO,oBAACA,iBAAD,EAAU,SAAkB,CAAA;AACrC;AAEA,MAAM,eAAeC;AA+BrB,IAAI,UAAUA;AACd,IAAI,WAAW;AACf,IAAI,QAAQC;AACZ,IAAI,SAASC;AACb,IAAI,MAAMC"}
1
+ {"version":3,"file":"index.js","names":["Context","LivePreview","LiveError","LiveEditor","LiveDnd"],"sources":["../src/index.tsx"],"sourcesContent":["import './index.css';\n\nimport Context from './components/context';\nimport LiveDnd, {\n type DndEditError,\n type DndItems,\n type DndItemsItem,\n type DndItemsOptions,\n type DndLayout,\n type DndPalette,\n type DndPanel,\n type DndRenderField,\n type DndRenderSectionFallback,\n type DndSectionFallbackArgs,\n type FieldProps,\n type ItemsEditor,\n type ItemsEditorItem,\n type ItemsEditorOptions,\n type PanelBinding,\n type PanelNodeChange,\n type PanelNodesChange,\n} from './components/dnd';\nimport LiveEditor, { type EditorRenderData } from './components/editor';\nimport LiveError from './components/error';\nimport { type FrameProps } from './components/frame';\nimport LivePreview from './components/preview';\nimport type { Section } from './types';\n\nconst App = ({ children }: { children?: React.ReactNode }) => {\n return <Context>{children}</Context>;\n};\n\nconst LiveRenderer = LivePreview;\n\nexport {\n LivePreview,\n LiveError,\n LiveEditor,\n LiveDnd,\n LiveRenderer,\n App as LiveProvider,\n //\n};\n\nexport type {\n DndEditError,\n DndRenderField,\n DndRenderSectionFallback,\n DndSectionFallbackArgs,\n DndPalette,\n DndPanel,\n DndLayout,\n PanelBinding,\n PanelNodeChange,\n PanelNodesChange,\n FieldProps,\n DndItems,\n DndItemsItem,\n DndItemsOptions,\n // Deprecated aliases of the three above, kept until the next major.\n ItemsEditor,\n ItemsEditorItem,\n ItemsEditorOptions,\n EditorRenderData,\n FrameProps,\n Section,\n};\n\nApp.Preview = LivePreview;\nApp.Renderer = LiveRenderer;\nApp.Error = LiveError;\nApp.Editor = LiveEditor;\nApp.Dnd = LiveDnd;\n\nexport default App;\n"],"mappings":";;;;;;;AA4BA,MAAM,OAAO,EAAE,eAA+C;CAC5D,OAAO,oBAACA,iBAAD,EAAU,SAAkB,CAAA;AACrC;AAEA,MAAM,eAAeC;AAoCrB,IAAI,UAAUA;AACd,IAAI,WAAW;AACf,IAAI,QAAQC;AACZ,IAAI,SAASC;AACb,IAAI,MAAMC"}
@@ -1,3 +1,3 @@
1
- import { r as baseModules } from "../use-dynamic-tailwind-DuGLeDR3.js";
2
- import { t as Preview } from "../preview-BwEfltgi.js";
1
+ import { r as baseModules } from "../use-dynamic-tailwind-BDfytfYC.js";
2
+ import { t as Preview } from "../preview-B9Jhv1Up.js";
3
3
  export { baseModules, Preview as default };
@@ -1,6 +1,6 @@
1
1
  import { i as usePreview, r as useError } from "./states-Ci1AvoQ9.js";
2
2
  import { t as cn } from "./cn-CAnad2vL.js";
3
- import { a as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-DuGLeDR3.js";
3
+ import { a as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-BDfytfYC.js";
4
4
  import { t as Error } from "./error-KW8XCcjH.js";
5
5
  import { useMemo } from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -83,4 +83,4 @@ const Preview = ({ code, props = NO_PROPS, modules = NO_MODULES, dynamicTailwind
83
83
  //#endregion
84
84
  export { Preview as t };
85
85
 
86
- //# sourceMappingURL=preview-BwEfltgi.js.map
86
+ //# sourceMappingURL=preview-B9Jhv1Up.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview-BwEfltgi.js","names":["LiveError"],"sources":["../src/components/preview/defaults.ts","../src/components/preview/client.tsx","../src/components/preview/preview.tsx"],"sourcesContent":["// Stable defaults for optional object props. A `= {}` default is a new\n// object on every render, which re-runs every memo keyed on it — the merged\n// module map, and so `compile()` — even when the caller passed nothing (#348).\nexport const NO_PROPS: Record<string, unknown> = {};\nexport const NO_MODULES: Record<string, unknown> = {};\n","'use client';\n\nimport { useMemo } from 'react';\n\nimport { useError, usePreview } from '~/components/context/states';\nimport LiveError from '~/components/error';\nimport Frame, { type FrameProps } from '~/components/frame';\nimport { cn } from '~/utils/cn';\n\nimport { NO_MODULES, NO_PROPS } from './defaults';\nimport { type Props } from './preview';\nimport { useCompiledModule } from './use-compiled-module';\nimport { useDynamicTailwind } from './use-dynamic-tailwind';\n\nconst Client = ({\n code: _code,\n className,\n showError,\n props = NO_PROPS,\n modules = NO_MODULES,\n frame,\n dynamicTailwind = false,\n provider,\n}: Props) => {\n const { code } = usePreview();\n const { error, setError } = useError();\n const isError = !!showError && !!error;\n\n const classNames = cn(isError && 'hidden', className);\n\n const effectiveCode = _code === undefined ? code : _code;\n\n const module = useCompiledModule(effectiveCode, modules);\n\n // Attached to the wrapper below; scans the rendered DOM so classes coming\n // from an imported component are picked up too. See the hook for details.\n const { ref: contentRef, css: dynamicCSS } = useDynamicTailwind(\n effectiveCode,\n dynamicTailwind,\n );\n\n const componentProps = useMemo(\n () => ({\n ...props,\n }),\n [props],\n );\n\n const renderProvider = (component: React.ReactNode) => {\n return provider ? provider(component) : component;\n };\n\n if (module && module.error) {\n return (\n <>\n <div className={cn('relative h-full w-full', classNames)}>\n <LiveError message={module.error} title=\"Compile Error\" />\n </div>\n <LiveError.Runtime open={isError} />\n </>\n );\n }\n\n const Component = module?.exports?.default;\n\n if (!Component) {\n return null;\n }\n\n return (\n <>\n {frame ? (\n <div className={cn('h-full w-full', classNames)}>\n <Frame {...(frame as FrameProps)}>\n {container => (\n <div ref={contentRef} style={{ display: 'contents' }}>\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={(e: Error) => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} container={container} />\n {dynamicTailwind && dynamicCSS && (\n <style>{dynamicCSS}</style>\n )}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n </Frame>\n </div>\n ) : (\n <div\n ref={contentRef}\n className={cn(\n 'relative h-full w-full overflow-x-hidden overflow-y-auto',\n classNames,\n )}\n style={{\n isolation: 'isolate',\n transform: 'translateZ(0)',\n containerType: 'inline-size',\n }}\n >\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={e => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} />\n {dynamicTailwind && dynamicCSS && <style>{dynamicCSS}</style>}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n <LiveError.Runtime open={isError} />\n </>\n );\n};\n\nexport default Client;\n","import type React from 'react';\n\nimport type { FrameProps } from '../frame';\nimport Client from './client';\nimport { NO_MODULES, NO_PROPS } from './defaults';\n\nexport interface Props extends React.ComponentPropsWithRef<'div'> {\n code?: string;\n showError?: boolean;\n props?: Record<string, unknown>;\n container?: HTMLElement | null;\n frame?: boolean | FrameProps;\n modules?: Record<string, unknown>;\n dynamicTailwind?: boolean;\n provider?: (children: React.ReactNode) => React.ReactNode;\n}\n\n// A thin wrapper around Client, which does the actual compiling, error\n// handling, and frame wrapping. This used to have its own duplicate\n// compile-and-render branch for the `code` prop that never wrapped its\n// output in <Frame>, so `frame` was silently ignored whenever `code` was\n// passed — see #187. Client already handles `code` (falling back to\n// context when absent) and `frame`, so there is only one render path now.\nconst Preview = ({\n code,\n props = NO_PROPS,\n modules = NO_MODULES,\n dynamicTailwind = false,\n provider,\n ...restProps\n}: Props) => {\n return (\n <Client\n code={code}\n props={props}\n modules={modules}\n dynamicTailwind={dynamicTailwind}\n provider={provider}\n {...restProps}\n />\n );\n};\n\nexport default Preview;\n"],"mappings":";;;;;;;AAGA,MAAa,WAAoC,CAAC;AAClD,MAAa,aAAsC,CAAC;;;ACUpD,MAAM,UAAU,EACd,MAAM,OACN,WACA,WACA,QAAQ,UACR,UAAU,YACV,OACA,kBAAkB,OAClB,eACW;CACX,MAAM,EAAE,SAAS,WAAW;CAC5B,MAAM,EAAE,OAAO,aAAa,SAAS;CACrC,MAAM,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC;CAEjC,MAAM,aAAa,GAAG,WAAW,UAAU,SAAS;CAEpD,MAAM,gBAAgB,UAAU,KAAA,IAAY,OAAO;CAEnD,MAAM,SAAS,kBAAkB,eAAe,OAAO;CAIvD,MAAM,EAAE,KAAK,YAAY,KAAK,eAAe,mBAC3C,eACA,eACF;CAEA,MAAM,iBAAiB,eACd,EACL,GAAG,MACL,IACA,CAAC,KAAK,CACR;CAEA,MAAM,kBAAkB,cAA+B;EACrD,OAAO,WAAW,SAAS,SAAS,IAAI;CAC1C;CAEA,IAAI,UAAU,OAAO,OACnB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;EAAK,WAAW,GAAG,0BAA0B,UAAU;EACrD,UAAA,oBAACA,OAAD;GAAW,SAAS,OAAO;GAAO,OAAM;EAAiB,CAAA;CACtD,CAAA,GACL,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;CAIN,MAAM,YAAY,QAAQ,SAAS;CAEnC,IAAI,CAAC,WACH,OAAO;CAGT,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,QACC,oBAAC,OAAD;EAAK,WAAW,GAAG,iBAAiB,UAAU;EAC5C,UAAA,oBAAC,OAAD;GAAO,GAAK;GACT,WAAA,cACC,oBAAC,OAAD;IAAK,KAAK;IAAY,OAAO,EAAE,SAAS,WAAW;IACjD,UAAA,oBAACA,MAAU,UAAX;KACE,WAAW,CAAC,aAAa;KACzB,UAAU,MAAa,SAAS,EAAE,OAAO;KAExC,UAAA,eACC,qBAACA,MAAU,OAAX;MAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;MAAjD,UAAA,CACE,oBAAC,WAAD;OAAW,GAAI;OAA2B;MAAY,CAAA,GACrD,mBAAmB,cAClB,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAEb;KACnB,CAAA,CAAA;IACkB,CAAA;GACjB,CAAA;EAEF,CAAA;CACJ,CAAA,IAEL,oBAAC,OAAD;EACE,KAAK;EACL,WAAW,GACT,4DACA,UACF;EACA,OAAO;GACL,WAAW;GACX,WAAW;GACX,eAAe;EACjB;EAEA,UAAA,oBAACA,MAAU,UAAX;GACE,WAAW,CAAC,aAAa;GACzB,UAAS,MAAK,SAAS,EAAE,OAAO;GAE/B,UAAA,eACC,qBAACA,MAAU,OAAX;IAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;IAAjD,UAAA,CACE,oBAAC,WAAD,EAAW,GAAI,eAAiB,CAAA,GAC/B,mBAAmB,cAAc,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAC7C;GACnB,CAAA,CAAA;EACkB,CAAA;CACjB,CAAA,GAEP,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;AAEN;;;ACnGA,MAAM,WAAW,EACf,MACA,QAAQ,UACR,UAAU,YACV,kBAAkB,OAClB,UACA,GAAG,gBACQ;CACX,OACE,oBAAC,QAAD;EACQ;EACC;EACE;EACQ;EACP;EACV,GAAI;CACL,CAAA;AAEL"}
1
+ {"version":3,"file":"preview-B9Jhv1Up.js","names":["LiveError"],"sources":["../src/components/preview/defaults.ts","../src/components/preview/client.tsx","../src/components/preview/preview.tsx"],"sourcesContent":["// Stable defaults for optional object props. A `= {}` default is a new\n// object on every render, which re-runs every memo keyed on it — the merged\n// module map, and so `compile()` — even when the caller passed nothing (#348).\nexport const NO_PROPS: Record<string, unknown> = {};\nexport const NO_MODULES: Record<string, unknown> = {};\n","'use client';\n\nimport { useMemo } from 'react';\n\nimport { useError, usePreview } from '~/components/context/states';\nimport LiveError from '~/components/error';\nimport Frame, { type FrameProps } from '~/components/frame';\nimport { cn } from '~/utils/cn';\n\nimport { NO_MODULES, NO_PROPS } from './defaults';\nimport { type Props } from './preview';\nimport { useCompiledModule } from './use-compiled-module';\nimport { useDynamicTailwind } from './use-dynamic-tailwind';\n\nconst Client = ({\n code: _code,\n className,\n showError,\n props = NO_PROPS,\n modules = NO_MODULES,\n frame,\n dynamicTailwind = false,\n provider,\n}: Props) => {\n const { code } = usePreview();\n const { error, setError } = useError();\n const isError = !!showError && !!error;\n\n const classNames = cn(isError && 'hidden', className);\n\n const effectiveCode = _code === undefined ? code : _code;\n\n const module = useCompiledModule(effectiveCode, modules);\n\n // Attached to the wrapper below; scans the rendered DOM so classes coming\n // from an imported component are picked up too. See the hook for details.\n const { ref: contentRef, css: dynamicCSS } = useDynamicTailwind(\n effectiveCode,\n dynamicTailwind,\n );\n\n const componentProps = useMemo(\n () => ({\n ...props,\n }),\n [props],\n );\n\n const renderProvider = (component: React.ReactNode) => {\n return provider ? provider(component) : component;\n };\n\n if (module && module.error) {\n return (\n <>\n <div className={cn('relative h-full w-full', classNames)}>\n <LiveError message={module.error} title=\"Compile Error\" />\n </div>\n <LiveError.Runtime open={isError} />\n </>\n );\n }\n\n const Component = module?.exports?.default;\n\n if (!Component) {\n return null;\n }\n\n return (\n <>\n {frame ? (\n <div className={cn('h-full w-full', classNames)}>\n <Frame {...(frame as FrameProps)}>\n {container => (\n <div ref={contentRef} style={{ display: 'contents' }}>\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={(e: Error) => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} container={container} />\n {dynamicTailwind && dynamicCSS && (\n <style>{dynamicCSS}</style>\n )}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n </Frame>\n </div>\n ) : (\n <div\n ref={contentRef}\n className={cn(\n 'relative h-full w-full overflow-x-hidden overflow-y-auto',\n classNames,\n )}\n style={{\n isolation: 'isolate',\n transform: 'translateZ(0)',\n containerType: 'inline-size',\n }}\n >\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={e => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} />\n {dynamicTailwind && dynamicCSS && <style>{dynamicCSS}</style>}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n <LiveError.Runtime open={isError} />\n </>\n );\n};\n\nexport default Client;\n","import type React from 'react';\n\nimport type { FrameProps } from '../frame';\nimport Client from './client';\nimport { NO_MODULES, NO_PROPS } from './defaults';\n\nexport interface Props extends React.ComponentPropsWithRef<'div'> {\n code?: string;\n showError?: boolean;\n props?: Record<string, unknown>;\n container?: HTMLElement | null;\n frame?: boolean | FrameProps;\n modules?: Record<string, unknown>;\n dynamicTailwind?: boolean;\n provider?: (children: React.ReactNode) => React.ReactNode;\n}\n\n// A thin wrapper around Client, which does the actual compiling, error\n// handling, and frame wrapping. This used to have its own duplicate\n// compile-and-render branch for the `code` prop that never wrapped its\n// output in <Frame>, so `frame` was silently ignored whenever `code` was\n// passed — see #187. Client already handles `code` (falling back to\n// context when absent) and `frame`, so there is only one render path now.\nconst Preview = ({\n code,\n props = NO_PROPS,\n modules = NO_MODULES,\n dynamicTailwind = false,\n provider,\n ...restProps\n}: Props) => {\n return (\n <Client\n code={code}\n props={props}\n modules={modules}\n dynamicTailwind={dynamicTailwind}\n provider={provider}\n {...restProps}\n />\n );\n};\n\nexport default Preview;\n"],"mappings":";;;;;;;AAGA,MAAa,WAAoC,CAAC;AAClD,MAAa,aAAsC,CAAC;;;ACUpD,MAAM,UAAU,EACd,MAAM,OACN,WACA,WACA,QAAQ,UACR,UAAU,YACV,OACA,kBAAkB,OAClB,eACW;CACX,MAAM,EAAE,SAAS,WAAW;CAC5B,MAAM,EAAE,OAAO,aAAa,SAAS;CACrC,MAAM,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC;CAEjC,MAAM,aAAa,GAAG,WAAW,UAAU,SAAS;CAEpD,MAAM,gBAAgB,UAAU,KAAA,IAAY,OAAO;CAEnD,MAAM,SAAS,kBAAkB,eAAe,OAAO;CAIvD,MAAM,EAAE,KAAK,YAAY,KAAK,eAAe,mBAC3C,eACA,eACF;CAEA,MAAM,iBAAiB,eACd,EACL,GAAG,MACL,IACA,CAAC,KAAK,CACR;CAEA,MAAM,kBAAkB,cAA+B;EACrD,OAAO,WAAW,SAAS,SAAS,IAAI;CAC1C;CAEA,IAAI,UAAU,OAAO,OACnB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;EAAK,WAAW,GAAG,0BAA0B,UAAU;EACrD,UAAA,oBAACA,OAAD;GAAW,SAAS,OAAO;GAAO,OAAM;EAAiB,CAAA;CACtD,CAAA,GACL,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;CAIN,MAAM,YAAY,QAAQ,SAAS;CAEnC,IAAI,CAAC,WACH,OAAO;CAGT,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,QACC,oBAAC,OAAD;EAAK,WAAW,GAAG,iBAAiB,UAAU;EAC5C,UAAA,oBAAC,OAAD;GAAO,GAAK;GACT,WAAA,cACC,oBAAC,OAAD;IAAK,KAAK;IAAY,OAAO,EAAE,SAAS,WAAW;IACjD,UAAA,oBAACA,MAAU,UAAX;KACE,WAAW,CAAC,aAAa;KACzB,UAAU,MAAa,SAAS,EAAE,OAAO;KAExC,UAAA,eACC,qBAACA,MAAU,OAAX;MAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;MAAjD,UAAA,CACE,oBAAC,WAAD;OAAW,GAAI;OAA2B;MAAY,CAAA,GACrD,mBAAmB,cAClB,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAEb;KACnB,CAAA,CAAA;IACkB,CAAA;GACjB,CAAA;EAEF,CAAA;CACJ,CAAA,IAEL,oBAAC,OAAD;EACE,KAAK;EACL,WAAW,GACT,4DACA,UACF;EACA,OAAO;GACL,WAAW;GACX,WAAW;GACX,eAAe;EACjB;EAEA,UAAA,oBAACA,MAAU,UAAX;GACE,WAAW,CAAC,aAAa;GACzB,UAAS,MAAK,SAAS,EAAE,OAAO;GAE/B,UAAA,eACC,qBAACA,MAAU,OAAX;IAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;IAAjD,UAAA,CACE,oBAAC,WAAD,EAAW,GAAI,eAAiB,CAAA,GAC/B,mBAAmB,cAAc,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAC7C;GACnB,CAAA,CAAA;EACkB,CAAA;CACjB,CAAA,GAEP,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;AAEN;;;ACnGA,MAAM,WAAW,EACf,MACA,QAAQ,UACR,UAAU,YACV,kBAAkB,OAClB,UACA,GAAG,gBACQ;CACX,OACE,oBAAC,QAAD;EACQ;EACC;EACE;EACQ;EACP;EACV,GAAI;CACL,CAAA;AAEL"}
@@ -1,2 +1,2 @@
1
- import { t as ContextProvider } from "../context-DQ-UtoyS.js";
1
+ import { t as ContextProvider } from "../context-93X3gyfJ.js";
2
2
  export { ContextProvider as default };
@@ -0,0 +1,24 @@
1
+ import { a as generateSectionPreview, l as parseDocument, o as generateSectionPreviews, s as getSections, u as replaceDocumentSections } from "./document-C3eCRQlj.js";
2
+ import { i as DEFAULT_CONTAINER_ID, u as documentTemplate } from "./constants-CKvdqZtO.js";
3
+ //#region src/utils/sections.ts
4
+ const extractSections = (code, options) => {
5
+ const doc = parseDocument(code, options);
6
+ return doc ? getSections(doc, options) : [];
7
+ };
8
+ const replaceSections = (code, sections, options) => {
9
+ return replaceDocumentSections(code, sections, options);
10
+ };
11
+ const generateSection = (code, fullCode, options) => {
12
+ return generateSectionPreview(fullCode, code, options);
13
+ };
14
+ const generateSections = (codes, fullCode, options) => {
15
+ return generateSectionPreviews(fullCode, codes, options);
16
+ };
17
+ const createDocument = ({ containerId = DEFAULT_CONTAINER_ID } = {}) => {
18
+ if (!/^[^\s"'<>{}]+$/.test(containerId)) throw new Error(`createDocument: containerId must be a plain element id, got ${JSON.stringify(containerId)}`);
19
+ return documentTemplate(containerId);
20
+ };
21
+ //#endregion
22
+ export { replaceSections as a, generateSections as i, extractSections as n, generateSection as r, createDocument as t };
23
+
24
+ //# sourceMappingURL=sections-A4TAXUP8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sections-A4TAXUP8.js","names":[],"sources":["../src/utils/sections.ts"],"sourcesContent":["import { DEFAULT_CONTAINER_ID, documentTemplate } from '~/constants';\nimport type { Section } from '~/types';\n\nimport {\n type DocumentOptions,\n type SectionOptions,\n createSectionPreviewCache,\n generateSectionPreview,\n generateSectionPreviews,\n getSections,\n parseDocument,\n replaceDocumentSections,\n} from './ast/document';\n\nexport const extractSections = (\n code: string,\n options?: SectionOptions,\n): Section[] => {\n const doc = parseDocument(code, options);\n\n return doc ? getSections(doc, options) : [];\n};\n\nexport const replaceSections = (\n code: string,\n sections: string[],\n options?: DocumentOptions,\n): string => {\n return replaceDocumentSections(code, sections, options);\n};\n\nexport const generateSection = (\n code: string,\n fullCode: string,\n options?: DocumentOptions,\n) => {\n return generateSectionPreview(fullCode, code, options);\n};\n\n// Batched form of generateSection() — computes every section's preview from\n// a single parse of fullCode instead of one parseDocument call per section\n// (see generateSectionPreviews). Unchanged sections come back byte-identical\n// to their previous preview string, which is what lets a caller pass each\n// one down as a stable prop (see Renderer's React.memo).\nexport const generateSections = (\n codes: string[],\n fullCode: string,\n options?: DocumentOptions,\n): string[] => {\n return generateSectionPreviews(fullCode, codes, options);\n};\n\n// A new, empty document `Live.Dnd` can add sections to: an `App` component\n// rendering the container element and nothing else. Start a controlled\n// `Live.Dnd` from this rather than an empty string, which has no container,\n// so nothing dropped on the canvas would land anywhere (#449). Pass the same\n// `containerId` you give `Live.Dnd`.\nexport const createDocument = ({\n containerId = DEFAULT_CONTAINER_ID,\n}: DocumentOptions = {}): string => {\n // The id is written into a JSX attribute as-is, so anything that could end\n // the attribute or the tag is refused rather than producing broken source.\n if (!/^[^\\s\"'<>{}]+$/.test(containerId)) {\n throw new Error(\n `createDocument: containerId must be a plain element id, got ${JSON.stringify(containerId)}`,\n );\n }\n\n return documentTemplate(containerId);\n};\n\n// Incremental counterpart to generateSections() — see createSectionPreviewCache\n// (#131). Pass a fresh instance's `compute` in place of generateSections()\n// where the caller can keep it alive across renders (e.g. Dnd holds one via\n// `useState(() => createSectionPreviewCache())`).\nexport { createSectionPreviewCache };\nexport type {\n DocumentOptions,\n SectionOptions,\n SectionPreviewCache,\n} from './ast/document';\n"],"mappings":";;;AAcA,MAAa,mBACX,MACA,YACc;CACd,MAAM,MAAM,cAAc,MAAM,OAAO;CAEvC,OAAO,MAAM,YAAY,KAAK,OAAO,IAAI,CAAC;AAC5C;AAEA,MAAa,mBACX,MACA,UACA,YACW;CACX,OAAO,wBAAwB,MAAM,UAAU,OAAO;AACxD;AAEA,MAAa,mBACX,MACA,UACA,YACG;CACH,OAAO,uBAAuB,UAAU,MAAM,OAAO;AACvD;AAOA,MAAa,oBACX,OACA,UACA,YACa;CACb,OAAO,wBAAwB,UAAU,OAAO,OAAO;AACzD;AAOA,MAAa,kBAAkB,EAC7B,cAAc,yBACK,CAAC,MAAc;CAGlC,IAAI,CAAC,iBAAiB,KAAK,WAAW,GACpC,MAAM,IAAI,MACR,+DAA+D,KAAK,UAAU,WAAW,GAC3F;CAGF,OAAO,iBAAiB,WAAW;AACrC"}