@jbpark/live-editor 4.3.1 → 4.5.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 (69) hide show
  1. package/README.md +2 -2
  2. package/dist/{boundary-B17cepvm.js → boundary-DnjGgsK6.js} +8 -5
  3. package/dist/boundary-DnjGgsK6.js.map +1 -0
  4. package/dist/{compile-0Dvp8zp5.js → compile-DDfk5P25.js} +3 -3
  5. package/dist/{compile-0Dvp8zp5.js.map → compile-DDfk5P25.js.map} +1 -1
  6. package/dist/{constants-CKvdqZtO.js → constants-h1JAgOeW.js} +4 -2
  7. package/dist/constants-h1JAgOeW.js.map +1 -0
  8. package/dist/{context-93X3gyfJ.js → context-DsEXJl4h.js} +11 -5
  9. package/dist/context-DsEXJl4h.js.map +1 -0
  10. package/dist/{core-B3ruccKb.js → core-CRsAGpei.js} +2 -2
  11. package/dist/{core-B3ruccKb.js.map → core-CRsAGpei.js.map} +1 -1
  12. package/dist/{detect-typescript-5MV4mCM7.js → detect-typescript-CCj9ALXc.js} +2 -2
  13. package/dist/{detect-typescript-5MV4mCM7.js.map → detect-typescript-CCj9ALXc.js.map} +1 -1
  14. package/dist/dnd/index.d.ts +2 -2
  15. package/dist/dnd/index.js +1 -1
  16. package/dist/{dnd-x8Mvj--6.js → dnd-DGNp20Nk.js} +496 -307
  17. package/dist/dnd-DGNp20Nk.js.map +1 -0
  18. package/dist/{document-C-hGKMkk.js → document-DGHTfrda.js} +7739 -7736
  19. package/dist/document-DGHTfrda.js.map +1 -0
  20. package/dist/editor/index.js +2 -2
  21. package/dist/{editor-DvMruljw.js → editor-DQ8Q--qR.js} +2 -2
  22. package/dist/{editor-DvMruljw.js.map → editor-DQ8Q--qR.js.map} +1 -1
  23. package/dist/error/index.d.ts +1 -1
  24. package/dist/error/index.js +2 -2
  25. package/dist/{error-DWhxQEom.js → error-DwqwjJ2C.js} +13 -6
  26. package/dist/error-DwqwjJ2C.js.map +1 -0
  27. package/dist/index-CHknA6k1.d.ts +221 -0
  28. package/dist/{index-CtlUYnWq.d.ts → index-P9Aifaui.d.ts} +14 -4
  29. package/dist/index-WQgFy510.d.ts +11 -0
  30. package/dist/{index-C4SGQ3Ci.d.ts → index-vtyggWy0.d.ts} +4 -1
  31. package/dist/index.d.ts +18 -17
  32. package/dist/index.js +12 -8
  33. package/dist/index.js.map +1 -1
  34. package/dist/{ast-CehbCXwh.js → items-DdrwGxJw.js} +467 -426
  35. package/dist/items-DdrwGxJw.js.map +1 -0
  36. package/dist/messages-Cp3g1mn1.d.ts +129 -0
  37. package/dist/messages-CzUPVnzH.js +132 -0
  38. package/dist/messages-CzUPVnzH.js.map +1 -0
  39. package/dist/preview/index.js +2 -2
  40. package/dist/{preview-BYck9mVK.js → preview-BKFgq_5u.js} +6 -4
  41. package/dist/preview-BKFgq_5u.js.map +1 -0
  42. package/dist/provider/index.d.ts +3 -8
  43. package/dist/provider/index.js +3 -2
  44. package/dist/{sections-Ce63wbtG.js → sections-BRH3KHYc.js} +9 -4
  45. package/dist/sections-BRH3KHYc.js.map +1 -0
  46. package/dist/style.css +505 -21
  47. package/dist/{use-dynamic-tailwind-QKcGvUJs.js → use-dynamic-tailwind-T9r9ExbR.js} +21 -4
  48. package/dist/use-dynamic-tailwind-T9r9ExbR.js.map +1 -0
  49. package/dist/utils/ast/index.d.ts +3 -2
  50. package/dist/utils/ast/index.js +66 -3
  51. package/dist/utils/ast/index.js.map +1 -0
  52. package/dist/utils/index.d.ts +30 -13
  53. package/dist/utils/index.js +26 -6
  54. package/dist/utils/index.js.map +1 -0
  55. package/dist/validate-DB59Z_Nx.d.ts +100 -0
  56. package/dist/validate-iLo8IONY.js +64 -0
  57. package/dist/validate-iLo8IONY.js.map +1 -0
  58. package/package.json +3 -3
  59. package/dist/ast-CehbCXwh.js.map +0 -1
  60. package/dist/boundary-B17cepvm.js.map +0 -1
  61. package/dist/constants-CKvdqZtO.js.map +0 -1
  62. package/dist/context-93X3gyfJ.js.map +0 -1
  63. package/dist/dnd-x8Mvj--6.js.map +0 -1
  64. package/dist/document-C-hGKMkk.js.map +0 -1
  65. package/dist/error-DWhxQEom.js.map +0 -1
  66. package/dist/index-w3kLcCXl.d.ts +0 -255
  67. package/dist/preview-BYck9mVK.js.map +0 -1
  68. package/dist/sections-Ce63wbtG.js.map +0 -1
  69. package/dist/use-dynamic-tailwind-QKcGvUJs.js.map +0 -1
@@ -0,0 +1,132 @@
1
+ import { t as defaultValidationMessages } from "./validate-iLo8IONY.js";
2
+ import { createContext, useContext } from "react";
3
+ //#region src/components/context/messages.ts
4
+ const defaultMessages = {
5
+ section: {
6
+ moveUp: "Move section up",
7
+ moveDown: "Move section down",
8
+ duplicate: "Duplicate section",
9
+ delete: "Delete section"
10
+ },
11
+ canvas: {
12
+ palette: "Components",
13
+ properties: "Properties",
14
+ pickElement: "Pick an element",
15
+ pickElementActive: "Click an element to edit it. Esc to cancel.",
16
+ dropHere: "Drop here",
17
+ dropAtBottom: "Drag here to add at bottom",
18
+ empty: "No sections available",
19
+ emptyHintTouch: "Tap a component to add it",
20
+ emptyHintDrag: "Drag a component from the left to add it",
21
+ syntaxError: "The document has a syntax error",
22
+ syntaxErrorDetail: "Fix it in the code to see its sections",
23
+ missingContainer: (containerId) => `No #${containerId} element in the document`,
24
+ missingContainerDetail: (containerId) => `Sections go inside the element with id="${containerId}"`,
25
+ stale: "Showing the last version that parsed. Fix the syntax error in the code to edit here again."
26
+ },
27
+ panel: {
28
+ selectSection: "Please select a section.",
29
+ noEditableElements: "No editable elements.",
30
+ readOnly: "The document has a syntax error. These fields are from the last version that parsed, and can't be edited until it parses again.",
31
+ expressionPreserved: "This expression is preserved but is not editable here.",
32
+ useCodeEditor: "Use the code editor to change it.",
33
+ invalidValue: "Invalid value.",
34
+ urlPlaceholder: "https://example.com",
35
+ numberPlaceholder: "Enter a numeric value",
36
+ textPlaceholder: "Enter a value"
37
+ },
38
+ items: {
39
+ heading: (count) => `Items (${count})`,
40
+ add: "Add Item",
41
+ item: (position) => `Item ${position}`,
42
+ reorder: (item) => `Reorder ${item}`,
43
+ moveUp: "Move item up",
44
+ moveDown: "Move item down",
45
+ delete: "Delete item",
46
+ collapseAll: "Collapse all",
47
+ expandAll: "Expand all",
48
+ unreadable: "This value could not be read as a list. Edit it in the code editor.",
49
+ empty: "No editable items. The panel copies an existing item rather than guessing the shape of a new one — add the first item in the code editor.",
50
+ structureLocked: "Values remain editable, but moving, copying, adding, and deleting require a dense array without spreads or parenthesized top-level items. Use the code editor for those structural changes.",
51
+ noNestedBindings: "No JSX bindings found"
52
+ },
53
+ children: {
54
+ heading: (count) => `Children Items (${count})`,
55
+ add: "Add Child",
56
+ child: (position, tagName) => `Child ${position} (${tagName})`,
57
+ moveUp: "Move child up",
58
+ moveDown: "Move child down",
59
+ delete: "Delete child",
60
+ editableBindings: "Editable Bindings:",
61
+ childNodes: "Child Nodes:"
62
+ },
63
+ selection: {
64
+ count: (count) => `${count} selected`,
65
+ duplicate: "Duplicate selected",
66
+ moveUp: "Move selected up",
67
+ moveDown: "Move selected down",
68
+ delete: "Delete selected",
69
+ clear: "Clear"
70
+ },
71
+ editErrors: {
72
+ updateFailed: (label) => `Failed to update "${label}"`,
73
+ cannotEdit: (label) => `Cannot edit "${label}" in the panel`,
74
+ cannotRemove: (label) => `Cannot remove "${label}"`,
75
+ attributeNotFound: (property) => `This element has no "${property}" attribute — check the property in its data-binding.`,
76
+ bindingNotDeclared: ({ label, property }) => `No binding for ${property ? `property "${property}"` : `label "${label}"`} is declared on this element's data-binding.`,
77
+ duplicateBinding: ({ count, label, property }) => `${count} bindings share ${property ? `property "${property}"` : `label "${label}"`} on this element — remove the duplicate in its data-binding.`,
78
+ reservedProperty: (property) => `"${property}" is managed by the editor, so a binding can't change it.`,
79
+ requiredProperty: (property) => `"${property}" is marked required in its data-binding, so it can't be removed.`,
80
+ noBinding: "This element has no data-binding declaration.",
81
+ elementNotFound: "The target element could not be found in this section.",
82
+ unsupportedSyntax: (property) => `The "${property}" expression was preserved. Change it in the code editor instead.`,
83
+ checkConsole: "Check the console for details.",
84
+ syntaxError: "The document has a syntax error",
85
+ syntaxErrorDetail: "The canvas shows the last version that parsed. Fix the error in the code, then edit here again.",
86
+ missingContainer: (containerId) => `No #${containerId} element in the document`,
87
+ missingContainerDetail: (containerId) => `Sections are the <section> elements inside the element with id="${containerId}". Start from createDocument(), or set containerId to match your document.`,
88
+ sectionParseFailed: "Failed to parse this section",
89
+ itemsParseFailed: "Failed to parse items",
90
+ itemUpdateFailed: "Failed to update this item",
91
+ itemUpdateFailedDetail: "The source was preserved. Structural edits require a dense array without spreads; use the code editor for unsupported syntax."
92
+ },
93
+ announcements: {
94
+ instructions: "On a palette item, press Enter to add it to the canvas. On a canvas section, press Enter to select it, the up and down arrow keys to go to the previous or next section, and Delete to remove it. Press Space to pick a section up, the arrow keys to move it, and Space or Enter to drop it. Press Escape to cancel.",
95
+ section: "section",
96
+ pickedUp: (name) => `Picked up ${name}.`,
97
+ movedTo: (name, position, total) => `${name} moved to position ${position} of ${total}.`,
98
+ notOver: (name) => `${name} is no longer over a position.`,
99
+ droppedAt: (name, position, total) => `${name} dropped at position ${position} of ${total}.`,
100
+ dropped: (name) => `${name} dropped.`,
101
+ cancelled: (name) => `Moving ${name} was cancelled.`,
102
+ itemOver: (name, over) => `${name} is over ${over}.`,
103
+ itemMoved: (name, over) => `${name} was moved to the place of ${over}.`
104
+ },
105
+ errors: {
106
+ default: "An error occurred",
107
+ compile: "Compile Error",
108
+ runtime: "Runtime Error",
109
+ rendering: "Rendering Error",
110
+ sectionUnavailable: "Section Unavailable",
111
+ sectionNotRendered: "This section is not rendered in this editor.",
112
+ tryAgain: "Try Again",
113
+ unknown: "Unknown error",
114
+ unhandledRejection: "Unhandled promise rejection"
115
+ },
116
+ validation: defaultValidationMessages
117
+ };
118
+ const mergeMessages = (input, base = defaultMessages) => {
119
+ if (!input) return base;
120
+ const merged = { ...base };
121
+ for (const group of Object.keys(base)) if (input[group]) merged[group] = {
122
+ ...base[group],
123
+ ...input[group]
124
+ };
125
+ return merged;
126
+ };
127
+ const MessagesContext = createContext(defaultMessages);
128
+ const useLiveMessages = () => useContext(MessagesContext);
129
+ //#endregion
130
+ export { useLiveMessages as i, defaultMessages as n, mergeMessages as r, MessagesContext as t };
131
+
132
+ //# sourceMappingURL=messages-CzUPVnzH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages-CzUPVnzH.js","names":[],"sources":["../src/components/context/messages.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport {\n type ValidationMessages,\n defaultValidationMessages,\n} from '~/utils/ast/validate';\n\n// Every piece of text the editor shows or announces, grouped by where it\n// appears (#524). Text with values in it is a function, so a translation\n// can put them where its grammar needs them. Pass a partial set to `Live`'s\n// `messages` prop to replace any of it; the rest stays English.\nexport interface LiveMessages {\n // The section toolbar on the canvas and the panel header.\n section: {\n moveUp: string;\n moveDown: string;\n duplicate: string;\n delete: string;\n };\n canvas: {\n // The mobile palette button and Drawer title.\n palette: string;\n // The mobile panel Drawer title.\n properties: string;\n pickElement: string;\n pickElementActive: string;\n dropHere: string;\n dropAtBottom: string;\n empty: string;\n emptyHintTouch: string;\n emptyHintDrag: string;\n syntaxError: string;\n syntaxErrorDetail: string;\n missingContainer: (containerId: string) => string;\n missingContainerDetail: (containerId: string) => string;\n stale: string;\n };\n panel: {\n selectSection: string;\n noEditableElements: string;\n readOnly: string;\n expressionPreserved: string;\n useCodeEditor: string;\n invalidValue: string;\n urlPlaceholder: string;\n numberPlaceholder: string;\n textPlaceholder: string;\n };\n // The built-in editor for an array value.\n items: {\n heading: (count: number) => string;\n add: string;\n item: (position: number) => string;\n reorder: (item: string) => string;\n moveUp: string;\n moveDown: string;\n delete: string;\n collapseAll: string;\n expandAll: string;\n unreadable: string;\n empty: string;\n structureLocked: string;\n noNestedBindings: string;\n };\n // The built-in editor for child elements.\n children: {\n heading: (count: number) => string;\n add: string;\n child: (position: number, tagName: string) => string;\n moveUp: string;\n moveDown: string;\n delete: string;\n editableBindings: string;\n childNodes: string;\n };\n // The bar shown while items or children are selected.\n selection: {\n count: (count: number) => string;\n duplicate: string;\n moveUp: string;\n moveDown: string;\n delete: string;\n clear: string;\n };\n // The `title` and `description` of a `DndEditError`, which the default\n // toast shows.\n editErrors: {\n updateFailed: (label: string) => string;\n cannotEdit: (label: string) => string;\n cannotRemove: (label: string) => string;\n attributeNotFound: (property: string) => string;\n // `property` is set when the binding names one, otherwise `label` is the\n // one to show.\n bindingNotDeclared: (target: {\n label: string;\n property?: string;\n }) => string;\n duplicateBinding: (target: {\n count: number;\n label: string;\n property?: string;\n }) => string;\n reservedProperty: (property: string) => string;\n requiredProperty: (property: string) => string;\n noBinding: string;\n elementNotFound: string;\n unsupportedSyntax: (property: string) => string;\n checkConsole: string;\n syntaxError: string;\n syntaxErrorDetail: string;\n missingContainer: (containerId: string) => string;\n missingContainerDetail: (containerId: string) => string;\n sectionParseFailed: string;\n itemsParseFailed: string;\n itemUpdateFailed: string;\n itemUpdateFailedDetail: string;\n };\n // What a screen reader hears during a drag.\n announcements: {\n instructions: string;\n // Stands in for a section without a name.\n section: string;\n pickedUp: (name: string) => string;\n movedTo: (name: string, position: number, total: number) => string;\n notOver: (name: string) => string;\n droppedAt: (name: string, position: number, total: number) => string;\n dropped: (name: string) => string;\n cancelled: (name: string) => string;\n itemOver: (name: string, over: string) => string;\n itemMoved: (name: string, over: string) => string;\n };\n // The error boxes of `Live.Preview`, `Live.Error` and canvas sections.\n errors: {\n default: string;\n compile: string;\n runtime: string;\n rendering: string;\n sectionUnavailable: string;\n sectionNotRendered: string;\n tryAgain: string;\n // The message of a page error that carries none.\n unknown: string;\n // The message of an unhandled promise rejection that carries none.\n unhandledRejection: string;\n };\n validation: ValidationMessages;\n}\n\n// Every group of `LiveMessages`, each with any of its keys.\nexport type LiveMessagesInput = {\n [Group in keyof LiveMessages]?: Partial<LiveMessages[Group]>;\n};\n\nexport const defaultMessages: LiveMessages = {\n section: {\n moveUp: 'Move section up',\n moveDown: 'Move section down',\n duplicate: 'Duplicate section',\n delete: 'Delete section',\n },\n canvas: {\n palette: 'Components',\n properties: 'Properties',\n pickElement: 'Pick an element',\n pickElementActive: 'Click an element to edit it. Esc to cancel.',\n dropHere: 'Drop here',\n dropAtBottom: 'Drag here to add at bottom',\n empty: 'No sections available',\n emptyHintTouch: 'Tap a component to add it',\n emptyHintDrag: 'Drag a component from the left to add it',\n syntaxError: 'The document has a syntax error',\n syntaxErrorDetail: 'Fix it in the code to see its sections',\n missingContainer: containerId =>\n `No #${containerId} element in the document`,\n missingContainerDetail: containerId =>\n `Sections go inside the element with id=\"${containerId}\"`,\n stale:\n 'Showing the last version that parsed. Fix the syntax error in the code to edit here again.',\n },\n panel: {\n selectSection: 'Please select a section.',\n noEditableElements: 'No editable elements.',\n readOnly:\n \"The document has a syntax error. These fields are from the last version that parsed, and can't be edited until it parses again.\",\n expressionPreserved:\n 'This expression is preserved but is not editable here.',\n useCodeEditor: 'Use the code editor to change it.',\n invalidValue: 'Invalid value.',\n urlPlaceholder: 'https://example.com',\n numberPlaceholder: 'Enter a numeric value',\n textPlaceholder: 'Enter a value',\n },\n items: {\n heading: count => `Items (${count})`,\n add: 'Add Item',\n item: position => `Item ${position}`,\n reorder: item => `Reorder ${item}`,\n moveUp: 'Move item up',\n moveDown: 'Move item down',\n delete: 'Delete item',\n collapseAll: 'Collapse all',\n expandAll: 'Expand all',\n unreadable:\n 'This value could not be read as a list. Edit it in the code editor.',\n empty:\n 'No editable items. The panel copies an existing item rather than guessing the shape of a new one — add the first item in the code editor.',\n structureLocked:\n 'Values remain editable, but moving, copying, adding, and deleting require a dense array without spreads or parenthesized top-level items. Use the code editor for those structural changes.',\n noNestedBindings: 'No JSX bindings found',\n },\n children: {\n heading: count => `Children Items (${count})`,\n add: 'Add Child',\n child: (position, tagName) => `Child ${position} (${tagName})`,\n moveUp: 'Move child up',\n moveDown: 'Move child down',\n delete: 'Delete child',\n editableBindings: 'Editable Bindings:',\n childNodes: 'Child Nodes:',\n },\n selection: {\n count: count => `${count} selected`,\n duplicate: 'Duplicate selected',\n moveUp: 'Move selected up',\n moveDown: 'Move selected down',\n delete: 'Delete selected',\n clear: 'Clear',\n },\n editErrors: {\n updateFailed: label => `Failed to update \"${label}\"`,\n cannotEdit: label => `Cannot edit \"${label}\" in the panel`,\n cannotRemove: label => `Cannot remove \"${label}\"`,\n attributeNotFound: property =>\n `This element has no \"${property}\" attribute — check the property in its data-binding.`,\n bindingNotDeclared: ({ label, property }) =>\n `No binding for ${\n property ? `property \"${property}\"` : `label \"${label}\"`\n } is declared on this element's data-binding.`,\n duplicateBinding: ({ count, label, property }) =>\n `${count} bindings share ${\n property ? `property \"${property}\"` : `label \"${label}\"`\n } on this element — remove the duplicate in its data-binding.`,\n reservedProperty: property =>\n `\"${property}\" is managed by the editor, so a binding can't change it.`,\n requiredProperty: property =>\n `\"${property}\" is marked required in its data-binding, so it can't be removed.`,\n noBinding: 'This element has no data-binding declaration.',\n elementNotFound: 'The target element could not be found in this section.',\n unsupportedSyntax: property =>\n `The \"${property}\" expression was preserved. Change it in the code editor instead.`,\n checkConsole: 'Check the console for details.',\n syntaxError: 'The document has a syntax error',\n syntaxErrorDetail:\n 'The canvas shows the last version that parsed. Fix the error in the code, then edit here again.',\n missingContainer: containerId =>\n `No #${containerId} element in the document`,\n missingContainerDetail: containerId =>\n `Sections are the <section> elements inside the element with id=\"${containerId}\". Start from createDocument(), or set containerId to match your document.`,\n sectionParseFailed: 'Failed to parse this section',\n itemsParseFailed: 'Failed to parse items',\n itemUpdateFailed: 'Failed to update this item',\n itemUpdateFailedDetail:\n 'The source was preserved. Structural edits require a dense array without spreads; use the code editor for unsupported syntax.',\n },\n announcements: {\n instructions:\n 'On a palette item, press Enter to add it to the canvas. On a canvas section, press Enter to select it, the up and down arrow keys to go to the previous or next section, and Delete to remove it. Press Space to pick a section up, the arrow keys to move it, and Space or Enter to drop it. Press Escape to cancel.',\n section: 'section',\n pickedUp: name => `Picked up ${name}.`,\n movedTo: (name, position, total) =>\n `${name} moved to position ${position} of ${total}.`,\n notOver: name => `${name} is no longer over a position.`,\n droppedAt: (name, position, total) =>\n `${name} dropped at position ${position} of ${total}.`,\n dropped: name => `${name} dropped.`,\n cancelled: name => `Moving ${name} was cancelled.`,\n itemOver: (name, over) => `${name} is over ${over}.`,\n itemMoved: (name, over) => `${name} was moved to the place of ${over}.`,\n },\n errors: {\n default: 'An error occurred',\n compile: 'Compile Error',\n runtime: 'Runtime Error',\n rendering: 'Rendering Error',\n sectionUnavailable: 'Section Unavailable',\n sectionNotRendered: 'This section is not rendered in this editor.',\n tryAgain: 'Try Again',\n unknown: 'Unknown error',\n unhandledRejection: 'Unhandled promise rejection',\n },\n validation: defaultValidationMessages,\n};\n\n// `base` (the defaults, unless given) with each group's given keys on top.\nexport const mergeMessages = (\n input?: LiveMessagesInput,\n base: LiveMessages = defaultMessages,\n): LiveMessages => {\n if (!input) {\n return base;\n }\n\n const merged = { ...base };\n\n for (const group of Object.keys(base) as (keyof LiveMessages)[]) {\n if (input[group]) {\n merged[group] = { ...base[group], ...input[group] } as never;\n }\n }\n\n return merged;\n};\n\n// The English defaults outside a provider, so an error box rendered on its\n// own still has text.\nexport const MessagesContext = createContext<LiveMessages>(defaultMessages);\n\n// The messages in effect: the provider's, merged over the defaults. A custom\n// palette or panel can use it to show the same text as the built-in ones.\nexport const useLiveMessages = () => useContext(MessagesContext);\n"],"mappings":";;;AAyJA,MAAa,kBAAgC;CAC3C,SAAS;EACP,QAAQ;EACR,UAAU;EACV,WAAW;EACX,QAAQ;CACV;CACA,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,UAAU;EACV,cAAc;EACd,OAAO;EACP,gBAAgB;EAChB,eAAe;EACf,aAAa;EACb,mBAAmB;EACnB,mBAAkB,gBAChB,OAAO,YAAY;EACrB,yBAAwB,gBACtB,2CAA2C,YAAY;EACzD,OACE;CACJ;CACA,OAAO;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,SAAS;EACT,WAAU,SAAQ,aAAa,KAAK;EACpC,UAAU,MAAM,UAAU,UACxB,GAAG,KAAK,qBAAqB,SAAS,MAAM,MAAM;EACpD,UAAS,SAAQ,GAAG,KAAK;EACzB,YAAY,MAAM,UAAU,UAC1B,GAAG,KAAK,uBAAuB,SAAS,MAAM,MAAM;EACtD,UAAS,SAAQ,GAAG,KAAK;EACzB,YAAW,SAAQ,UAAU,KAAK;EAClC,WAAW,MAAM,SAAS,GAAG,KAAK,WAAW,KAAK;EAClD,YAAY,MAAM,SAAS,GAAG,KAAK,6BAA6B,KAAK;CACvE;CACA,QAAQ;EACN,SAAS;EACT,SAAS;EACT,SAAS;EACT,WAAW;EACX,oBAAoB;EACpB,oBAAoB;EACpB,UAAU;EACV,SAAS;EACT,oBAAoB;CACtB;CACA,YAAY;AACd;AAGA,MAAa,iBACX,OACA,OAAqB,oBACJ;CACjB,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,SAAS,EAAE,GAAG,KAAK;CAEzB,KAAK,MAAM,SAAS,OAAO,KAAK,IAAI,GAClC,IAAI,MAAM,QACR,OAAO,SAAS;EAAE,GAAG,KAAK;EAAQ,GAAG,MAAM;CAAO;CAItD,OAAO;AACT;AAIA,MAAa,kBAAkB,cAA4B,eAAe;AAI1E,MAAa,wBAAwB,WAAW,eAAe"}
@@ -1,3 +1,3 @@
1
- import { r as baseModules } from "../use-dynamic-tailwind-QKcGvUJs.js";
2
- import { t as Preview } from "../preview-BYck9mVK.js";
1
+ import { r as baseModules } from "../use-dynamic-tailwind-T9r9ExbR.js";
2
+ import { t as Preview } from "../preview-BKFgq_5u.js";
3
3
  export { baseModules, Preview as default };
@@ -1,7 +1,8 @@
1
+ import { i as useLiveMessages } from "./messages-CzUPVnzH.js";
1
2
  import { i as usePreview, r as useError } from "./states-Ci1AvoQ9.js";
2
3
  import { t as cn } from "./cn-CAnad2vL.js";
3
- import { a as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-QKcGvUJs.js";
4
- import { t as Error } from "./error-DWhxQEom.js";
4
+ import { a as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-T9r9ExbR.js";
5
+ import { t as Error } from "./error-DwqwjJ2C.js";
5
6
  import { useMemo } from "react";
6
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
8
  //#region src/components/preview/defaults.ts
@@ -12,6 +13,7 @@ const NO_MODULES = {};
12
13
  const Client = ({ code: _code, className, showError, props = NO_PROPS, modules = NO_MODULES, frame, dynamicTailwind = false, provider }) => {
13
14
  const { code } = usePreview();
14
15
  const { error, setError } = useError();
16
+ const messages = useLiveMessages();
15
17
  const isError = !!showError && !!error;
16
18
  const classNames = cn(isError && "hidden", className);
17
19
  const effectiveCode = _code === void 0 ? code : _code;
@@ -25,7 +27,7 @@ const Client = ({ code: _code, className, showError, props = NO_PROPS, modules =
25
27
  className: cn("relative h-full w-full", classNames),
26
28
  children: /* @__PURE__ */ jsx(Error, {
27
29
  message: module.error,
28
- title: "Compile Error"
30
+ title: messages.errors.compile
29
31
  })
30
32
  }), /* @__PURE__ */ jsx(Error.Runtime, { open: isError })] });
31
33
  const Component = module?.exports?.default;
@@ -83,4 +85,4 @@ const Preview = ({ code, props = NO_PROPS, modules = NO_MODULES, dynamicTailwind
83
85
  //#endregion
84
86
  export { Preview as t };
85
87
 
86
- //# sourceMappingURL=preview-BYck9mVK.js.map
88
+ //# sourceMappingURL=preview-BKFgq_5u.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-BKFgq_5u.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 { useLiveMessages } from '~/components/context/messages';\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 messages = useLiveMessages();\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={messages.errors.compile} />\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;;;ACWpD,MAAM,UAAU,EACd,MAAM,OACN,WACA,WACA,QAAQ,UACR,UAAU,YACV,OACA,kBAAkB,OAClB,eACW;CACX,MAAM,EAAE,SAAS,WAAW;CAC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AQ,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;;;ACrGA,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,8 +1,3 @@
1
- import React from "react";
2
- //#region src/components/context/context.d.ts
3
- declare const ContextProvider: ({ children }: {
4
- children?: React.ReactNode;
5
- }) => React.JSX.Element;
6
- //#endregion
7
- export { ContextProvider as default };
8
- //# sourceMappingURL=index.d.ts.map
1
+ import { i as useLiveMessages, n as LiveMessagesInput, r as defaultMessages, t as LiveMessages } from "../messages-Cp3g1mn1.js";
2
+ import { n as Props, t as ContextProvider } from "../index-WQgFy510.js";
3
+ export { type LiveMessages, type LiveMessagesInput, type Props, ContextProvider as default, defaultMessages, useLiveMessages };
@@ -1,2 +1,3 @@
1
- import { t as ContextProvider } from "../context-93X3gyfJ.js";
2
- export { ContextProvider as default };
1
+ import { i as useLiveMessages, n as defaultMessages } from "../messages-CzUPVnzH.js";
2
+ import { t as ContextProvider } from "../context-DsEXJl4h.js";
3
+ export { ContextProvider as default, defaultMessages, useLiveMessages };
@@ -1,5 +1,5 @@
1
- import { a as generateSectionPreview, l as parseDocument, o as generateSectionPreviews, s as getSections, u as replaceDocumentSections } from "./document-C-hGKMkk.js";
2
- import { i as DEFAULT_CONTAINER_ID, u as documentTemplate } from "./constants-CKvdqZtO.js";
1
+ import { a as generateSectionPreview, c as inspectDocument, l as parseDocument, o as generateSectionPreviews, s as getSections, u as replaceDocumentSections } from "./document-DGHTfrda.js";
2
+ import { i as DEFAULT_CONTAINER_ID, u as documentTemplate } from "./constants-h1JAgOeW.js";
3
3
  //#region src/utils/sections.ts
4
4
  const extractSections = (code, options) => {
5
5
  const doc = parseDocument(code, options);
@@ -18,7 +18,12 @@ const createDocument = ({ containerId = DEFAULT_CONTAINER_ID } = {}) => {
18
18
  if (!/^[^\s"'<>{}]+$/.test(containerId)) throw new Error(`createDocument: containerId must be a plain element id, got ${JSON.stringify(containerId)}`);
19
19
  return documentTemplate(containerId);
20
20
  };
21
+ const checkDocument = (code, options) => {
22
+ const inspection = inspectDocument(code, options);
23
+ if (inspection.ok) return { ok: true };
24
+ return { ...inspection };
25
+ };
21
26
  //#endregion
22
- export { replaceSections as a, generateSections as i, extractSections as n, generateSection as r, createDocument as t };
27
+ export { generateSections as a, generateSection as i, createDocument as n, replaceSections as o, extractSections as r, checkDocument as t };
23
28
 
24
- //# sourceMappingURL=sections-Ce63wbtG.js.map
29
+ //# sourceMappingURL=sections-BRH3KHYc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sections-BRH3KHYc.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 DocumentProblem,\n type SectionOptions,\n createSectionPreviewCache,\n generateSectionPreview,\n generateSectionPreviews,\n getSections,\n inspectDocument,\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// Whether `Live.Dnd` can edit a document: it parses, and it has the\n// container. A host can check one before saving or loading it, and gets the\n// same reasons `Live.Dnd` reports through `onEditError` (#522).\nexport type DocumentCheck = { ok: true } | ({ ok: false } & DocumentProblem);\n\nexport const checkDocument = (\n code: string,\n options?: DocumentOptions,\n): DocumentCheck => {\n const inspection = inspectDocument(code, options);\n\n if (inspection.ok) {\n return { ok: true };\n }\n\n // A copy: the inspection is cached and shared with `Live.Dnd`.\n return { ...inspection };\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 DocumentProblem,\n SectionOptions,\n SectionPreviewCache,\n} from './ast/document';\n"],"mappings":";;;AAgBA,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;AAOA,MAAa,iBACX,MACA,YACkB;CAClB,MAAM,aAAa,gBAAgB,MAAM,OAAO;CAEhD,IAAI,WAAW,IACb,OAAO,EAAE,IAAI,KAAK;CAIpB,OAAO,EAAE,GAAG,WAAW;AACzB"}