@jbpark/live-editor 4.6.0 → 4.6.1

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.
@@ -1,227 +0,0 @@
1
- import { b as ExtractedNodeValue$1, c as BindingItem, d as BindingOptions, f as BindingRegistry, g as BindingType, l as BindingKeyMap, m as BindingRenderMap, v as DataAttrNode, x as NodeValueType$1, y as EditableNodeValueType$1 } from "./validate-DB59Z_Nx.js";
2
- import { C as ObjectExpression, S as Node, b as Expression, x as File, y as ArrayExpression } from "./document-Ct4jW78J.js";
3
- //#region node_modules/.pnpm/@babel+parser@7.29.9/node_modules/@babel/parser/typings/babel-parser.d.ts
4
- declare class Position {
5
- line: number;
6
- column: number;
7
- index: number;
8
- constructor(line: number, col: number, index: number);
9
- }
10
- type SyntaxPlugin = "flow" | "typescript" | "jsx" | "functionBind" | "pipelineOperator" | "placeholders";
11
- type ParseErrorCode = "BABEL_PARSER_SYNTAX_ERROR" | "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
12
- interface ParseErrorSpecification<ErrorDetails> {
13
- code: ParseErrorCode;
14
- reasonCode: string;
15
- syntaxPlugin?: SyntaxPlugin;
16
- missingPlugin?: string | string[];
17
- loc: Position;
18
- details: ErrorDetails;
19
- pos: number;
20
- }
21
- type ParseError$1<ErrorDetails> = SyntaxError & ParseErrorSpecification<ErrorDetails>;
22
- type ParseError = ParseError$1<object>;
23
- type ParseResult<Result extends File | Expression = File> = Result & {
24
- comments: File["comments"];
25
- errors: null | ParseError[];
26
- tokens?: File["tokens"];
27
- };
28
- //#endregion
29
- //#region src/utils/ast/extract.d.ts
30
- declare function extract(raw: string, options?: BindingOptions): DataAttrNode[];
31
- declare function clearExtractCache$1(): void;
32
- //#endregion
33
- //#region src/utils/ast/items.d.ts
34
- type ItemKind$1 = 'object' | 'primitive';
35
- interface ArrayItem$1 {
36
- index: number;
37
- kind: ItemKind$1;
38
- node: Expression;
39
- }
40
- //#endregion
41
- //#region src/utils/ast/binding.d.ts
42
- declare const findEditableChildren: (node: DataAttrNode) => DataAttrNode[];
43
- //#endregion
44
- //#region src/utils/ast/editable-value.d.ts
45
- type EditablePathSegment = string | number;
46
- type EditablePrimitive = string | number | boolean;
47
- interface EditableValueEntry {
48
- path: EditablePathSegment[];
49
- value: EditablePrimitive;
50
- }
51
- declare const flattenEditableValue: (value: string) => EditableValueEntry[] | null;
52
- declare const setEditableValue: (value: string, path: EditablePathSegment[], next: EditablePrimitive) => string;
53
- //#endregion
54
- //#region src/utils/ast/value.d.ts
55
- declare const parseValue: (value: unknown) => unknown;
56
- //#endregion
57
- //#region src/utils/ast/update.d.ts
58
- type UpdateFailure = {
59
- reason: 'element-not-found';
60
- dataId: string;
61
- } | {
62
- reason: 'no-binding';
63
- dataId: string;
64
- } | {
65
- reason: 'reserved-property';
66
- dataId: string;
67
- property: string;
68
- } | {
69
- reason: 'required-property';
70
- dataId: string;
71
- property: string;
72
- } | {
73
- reason: 'binding-not-declared';
74
- dataId: string;
75
- label: string;
76
- property?: string;
77
- } | {
78
- reason: 'duplicate-binding';
79
- dataId: string;
80
- label: string;
81
- property?: string;
82
- count: number;
83
- } | {
84
- reason: 'attribute-not-found';
85
- dataId: string;
86
- property: string;
87
- } | {
88
- reason: 'self-closing';
89
- dataId: string;
90
- property: string;
91
- } | {
92
- reason: 'unsupported-syntax';
93
- dataId: string;
94
- property: string;
95
- } | {
96
- reason: 'parse-error';
97
- error: unknown;
98
- };
99
- interface UpdateResult {
100
- code: string;
101
- success: boolean;
102
- failure?: UpdateFailure;
103
- failures?: UpdateFailure[];
104
- }
105
- declare const update: (code: string, dataId: string, label: string, value: unknown, property?: string, options?: BindingOptions) => UpdateResult;
106
- interface UpdateEntry {
107
- dataId: string;
108
- label: string;
109
- value: unknown;
110
- property?: string;
111
- }
112
- type UpdateAllResult = {
113
- success: true;
114
- code: string;
115
- } | {
116
- success: false;
117
- code: string;
118
- failure: UpdateFailure;
119
- index: number;
120
- };
121
- declare const updateAll: (raw: string, entries: UpdateEntry[], options?: BindingOptions) => UpdateAllResult;
122
- /**
123
- * @deprecated Not atomic: when an entry fails, the ones before and after it
124
- * are still applied, and the returned `code` carries them. Use `updateAll`,
125
- * which applies every entry or none. Will be removed in the next major.
126
- */
127
- declare const bulkUpdate: (raw: string, entries: UpdateEntry[]) => UpdateResult;
128
- //#endregion
129
- //#region src/utils/ast/children.d.ts
130
- type ChildrenAction = {
131
- type: 'move';
132
- from: number;
133
- to: number;
134
- } | {
135
- type: 'move-selected';
136
- indices: number[];
137
- direction: 'up' | 'down';
138
- } | {
139
- type: 'remove' | 'duplicate';
140
- indices: number[];
141
- } | {
142
- type: 'append';
143
- };
144
- interface ChildrenEdit {
145
- kind: 'children-edit';
146
- expected: string[];
147
- action: ChildrenAction;
148
- }
149
- declare const getChildrenSignatures: (nodes: DataAttrNode[]) => string[];
150
- //#endregion
151
- //#region src/utils/ast/index.d.ts
152
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
153
- declare const appendArrayItem: (code: string, kind: ItemKind$1, generateId?: () => string) => string | null;
154
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
155
- declare const duplicateArrayItems: (code: string, indices: Set<number>, generateId?: () => string) => string | null;
156
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
157
- declare const moveArrayItem: (code: string, from: number, to: number) => string | null;
158
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
159
- declare const moveArrayItems: (code: string, indices: Set<number>, direction: "up" | "down") => {
160
- code: string;
161
- indices: Set<number>;
162
- } | null;
163
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
164
- declare const parseItems: (code: string) => ArrayItem$1[] | null;
165
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
166
- declare const removeArrayItems: (code: string, indices: Set<number>, kind?: ItemKind$1) => string | null;
167
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
168
- declare const updateArrayItemProperty: (code: string, index: number, key: string, value: unknown, render?: BindingRenderMap) => string | null;
169
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
170
- declare const updateArrayItemValue: (code: string, index: number, value: unknown) => string | null;
171
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
172
- declare const parseArrayExpression: (value: string) => ArrayExpression | null;
173
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
174
- declare const arrayExpressionToCode: (elements: ObjectExpression[]) => string;
175
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
176
- declare const canStructurallyEditArray: (source: string) => boolean;
177
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
178
- type ArrayItem = ArrayItem$1;
179
- /** @deprecated Internal. Use `useDndItems` from `./dnd`. Removed in the next major. */
180
- type ItemKind = ItemKind$1;
181
- /** @deprecated Internal. Read values through `extract` or `PanelBinding.value`. Removed in the next major. */
182
- declare const extractNodeValue: (node: Node) => ExtractedNodeValue$1;
183
- /** @deprecated Internal. Read values through `extract` or `PanelBinding.value`. Removed in the next major. */
184
- declare const extractObjectProperties: (element: ObjectExpression) => Record<string, ExtractedNodeValue$1 & {
185
- astNode: Node;
186
- }>;
187
- /** @deprecated Internal. Write values through `update` or `PanelBinding.onChange`. Removed in the next major. */
188
- declare const createNodeFromValue: (type: NodeValueType$1, value: unknown) => Expression | null;
189
- /** @deprecated Internal. Check `PanelBinding.canEditValue` instead. Removed in the next major. */
190
- declare const canLosslesslyEvaluateSource: (source: string) => boolean;
191
- /** @deprecated Internal. Read values through `extract` or `PanelBinding.value`. Removed in the next major. */
192
- declare const getCurrentValue: (node: DataAttrNode, property: string) => string;
193
- /** @deprecated Internal. Read values through `extract` or `PanelBinding.value`. Removed in the next major. */
194
- declare const getStructuredValue: (node: DataAttrNode, property: string, type?: BindingType) => unknown;
195
- /** @deprecated Internal. Removed in the next major. */
196
- type ExtractedNodeValue = ExtractedNodeValue$1;
197
- /** @deprecated Internal. Removed in the next major. */
198
- type NodeValueType = NodeValueType$1;
199
- /** @deprecated Internal. Removed in the next major. */
200
- type EditableNodeValueType = EditableNodeValueType$1;
201
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
202
- declare const parseBinding: (bindingValue: string | null) => BindingItem[];
203
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
204
- declare const parseBindingExpression: (expression: ArrayExpression) => BindingItem[];
205
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
206
- declare const readNodeBindings: (node: DataAttrNode) => BindingItem[];
207
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
208
- declare const resolveBindings: (own: BindingItem[] | undefined, key: string | null | undefined, tagName: string, options?: BindingOptions) => BindingItem[];
209
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
210
- declare const getKeyBindings: (bindingKeys: BindingKeyMap | undefined, key: string) => BindingItem[] | undefined;
211
- /** @deprecated Internal. Read bindings through `extract` or `useDndPanel().bindings`. Removed in the next major. */
212
- declare const getRegistryBindings: (registry: BindingRegistry | undefined, tagName: string) => BindingItem[] | undefined;
213
- /** @deprecated Internal. Removed in the next major. */
214
- declare const isComponentTagName: (tagName: string) => boolean;
215
- /** @deprecated Internal. Removed in the next major. */
216
- declare const fillIds: (code: string, generateId?: () => string) => string;
217
- /** @deprecated Internal. Removed in the next major. */
218
- declare const replaceIds: (code: string, generateId?: () => string) => string;
219
- /** @deprecated Internal. Removed in the next major. */
220
- declare const clone: (element: Node, generateId?: () => string) => ParseResult<Expression>;
221
- /** @deprecated Internal. Removed in the next major. */
222
- declare const generateCode: (node: Node) => string;
223
- /** @deprecated Internal. Use `clearEditorCaches` from `./utils`. Removed in the next major. */
224
- declare const clearExtractCache: typeof clearExtractCache$1;
225
- //#endregion
226
- export { removeArrayItems as A, UpdateFailure as B, moveArrayItem as C, parseBindingExpression as D, parseBinding as E, ChildrenAction as F, parseValue as G, bulkUpdate as H, ChildrenEdit as I, EditableValueEntry as J, EditablePathSegment as K, getChildrenSignatures as L, resolveBindings as M, updateArrayItemProperty as N, parseItems as O, updateArrayItemValue as P, extract as Q, UpdateAllResult as R, isComponentTagName as S, parseArrayExpression as T, update as U, UpdateResult as V, updateAll as W, setEditableValue as X, flattenEditableValue as Y, findEditableChildren as Z, generateCode as _, NodeValueType as a, getRegistryBindings as b, canLosslesslyEvaluateSource as c, clone as d, createNodeFromValue as f, fillIds as g, extractObjectProperties as h, ItemKind as i, replaceIds as j, readNodeBindings as k, canStructurallyEditArray as l, extractNodeValue as m, EditableNodeValueType as n, appendArrayItem as o, duplicateArrayItems as p, EditablePrimitive as q, ExtractedNodeValue as r, arrayExpressionToCode as s, ArrayItem as t, clearExtractCache as u, getCurrentValue as v, moveArrayItems as w, getStructuredValue as x, getKeyBindings as y, UpdateEntry as z };
227
- //# sourceMappingURL=index-DKYUxi-E.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"items-B6OXxcLG.js","names":["t","parseExpression","parseExpression","t","t","parse","parseExpression","t","t","t","parseExpression","t","parse","t","t","parseExpression"],"sources":["../src/utils/ast/types.ts","../src/utils/ast/value.ts","../src/utils/ast/binding.ts","../src/utils/ast/extract.ts","../src/utils/selection.ts","../src/utils/ast/patch.ts","../src/utils/ast/children.ts","../src/utils/ast/value-expression.ts","../src/utils/ast/edit-source.ts","../src/utils/ast/update.ts","../src/utils/ast/array-source.ts","../src/utils/ast/items.ts"],"sourcesContent":["export interface Attribute {\n name: string;\n value: string | null;\n isStringLiteral?: boolean;\n}\n\nexport interface DataAttrNode {\n id?: string;\n tagName: string;\n attributes: Attribute[];\n dataAttributes: Attribute[];\n textContent: string;\n rawChildren?: string;\n // Exact structural child source, used to validate source-preserving edits.\n source?: string;\n loc?: {\n start: { line: number; column: number };\n end: { line: number; column: number };\n };\n children?: DataAttrNode[];\n isFragment?: boolean;\n bindings?: BindingItem[];\n}\n\nexport interface BindingOption {\n label: string;\n value: string;\n}\n\n// The kinds of data a binding can hold: what a value is, not how to draw\n// it. How to draw it is `widget`, which the library passes through without\n// reading; the built-in panel renders the default control for each kind.\nexport const BINDING_TYPES = [\n 'array',\n 'object',\n 'string',\n 'number',\n 'boolean',\n 'color',\n 'jsx',\n 'richtext',\n 'date',\n 'url',\n] as const;\n\nexport type BindingType = (typeof BINDING_TYPES)[number];\n\n// How to draw one field, as opposed to `type`, which is what its data is.\n// Written as a control name (`widget: 'slider'`) or as this object; parsing\n// turns the string into `{ type }`, so consumers see one shape.\n//\n// Constraints (`min`, `max`, `pattern`, `required`) stay on the binding, not\n// here, so `validateBindingValue` checks them with or without a widget.\nexport interface BindingWidget {\n // The control name, any string (such as `'slider'`). A custom panel\n // switches on it; the built-in panel ignores it.\n type: string;\n // Common presentation hints, typed.\n step?: number;\n unit?: string;\n // Any other config for the control, kept as written (#234).\n [key: string]: unknown;\n}\n\n// The fields a binding declares about itself. Shared by `BindingItem` and\n// render-map leaves, so a nested field can say everything a top-level one\n// can (#383).\nexport interface BindingFieldSpec {\n // What the value is. A closed set, because validation and parsing switch\n // on it.\n type?: BindingType;\n // How to draw it, always in object form. See `BindingWidget`.\n widget?: BindingWidget;\n options?: BindingOption[];\n render?: BindingRenderMap;\n min?: number;\n max?: number;\n pattern?: string;\n required?: boolean;\n // The app's own keys, anything not listed above, such as `group` or `tab`.\n // Kept apart so they can't collide with a field added later. Config for\n // the control goes in `widget` instead. `undefined` when there are none\n // (#234).\n meta?: Record<string, unknown>;\n}\n\n// A render-map entry is a leaf when it declares `type`, even an unknown\n// one, which then shows as an untyped field (#234). `label` and `property`\n// default to the entry's key.\nexport interface BindingRenderLeaf extends BindingFieldSpec {\n label?: string;\n property?: string;\n}\n\nexport interface BindingRenderMap {\n [key: string]: BindingRenderLeaf | BindingRenderMap;\n}\n\nexport interface BindingItem extends BindingFieldSpec {\n label: string;\n property: string;\n}\n\n// A component's tag name as written in the source: a member path\n// (`ui.Button`) or an identifier that doesn't start with a lowercase letter\n// (`Button`). Lowercase names are HTML elements.\nexport type BindingComponentName = `${string}.${string}` | Capitalize<string>;\n\n// One entry of `bindings` or `bindingKeys`, as written: a `BindingItem` plus\n// any key of the app's own (`group`, `tab`, `description`, ...), which\n// arrives in `binding.meta` just as it does from an inline `data-binding`.\n// `meta` itself isn't one of them: it's where those keys end up, so writing\n// it here would nest it under `meta.meta`.\nexport interface BindingSchema extends Omit<BindingItem, 'meta'> {\n [key: string]: unknown;\n}\n\n// Bindings for every element of a component, keyed by its tag name as\n// written, so markup doesn't have to repeat the same `data-binding` on each\n// one (#509). Components only: an entry for an HTML element such as `p` or\n// `h2` would make every one of them in every section editable, so those keys\n// are rejected by the type and ignored at runtime. An element's own\n// `data-binding`, even an empty one, takes precedence over its component's\n// entry. Matched elements still need a `data-id` to be edited.\nexport type BindingRegistry = Partial<\n Record<BindingComponentName, BindingSchema[]>\n>;\n\n// Bindings an element asks for by name, with `data-binding-key=\"hero-title\"`\n// in its markup, on an HTML element or a component alike (#513). Plain data,\n// so a host can load it from JSON or a CMS.\nexport type BindingKeyMap = Record<string, BindingSchema[]>;\n\n// Where bindings come from besides an element's own `data-binding`, in\n// order of precedence: the key its `data-binding-key` names in\n// `bindingKeys`, then its component's entry in `bindings`.\nexport interface BindingOptions {\n bindings?: BindingRegistry;\n bindingKeys?: BindingKeyMap;\n}\n\nexport type NodeValueType =\n 'boolean' | 'number' | 'string' | 'null' | 'array' | 'object' | 'unknown';\n\nexport type EditableNodeValueType = 'boolean' | 'number' | 'string' | 'null';\n\nexport interface ExtractedNodeValue {\n type: NodeValueType;\n value: string | number | boolean | null;\n}\n","import { parseExpression } from '@babel/parser';\nimport * as t from '@babel/types';\n\nimport { REGEX } from '../../constants';\nimport { generateCode } from './helpers';\nimport type { ExtractedNodeValue } from './types';\n\n// Reads values out of the AST without running code: literals, binding values\n// and array or object expressions.\n\nconst dedent = (str: string): string => {\n const lines = str\n .replace(/^\\n/, '')\n .replace(/\\n\\s*$/, '')\n .split('\\n');\n\n const indent = lines.reduce((min, line) => {\n if (!line.trim()) {\n return min;\n }\n const match = line.match(/^(\\s*)/);\n return Math.min(min, match?.[1]?.length ?? 0);\n }, Infinity);\n\n return indent === Infinity\n ? str.trim()\n : lines.map(line => line.slice(indent)).join('\\n');\n};\n\n// Removes type-only wrappers (`satisfies`, `as const`, type assertions) and\n// parentheses, so the literal underneath can be read. Without this, a\n// `data-binding={[...] satisfies BindingItem[]}` would read as no bindings.\nexport const unwrapExpression = (node: t.Node): t.Node => {\n let current = node;\n\n while (\n t.isTSAsExpression(current) ||\n t.isTSSatisfiesExpression(current) ||\n t.isTSNonNullExpression(current) ||\n t.isTSTypeAssertion(current) ||\n t.isParenthesizedExpression(current)\n ) {\n current = current.expression;\n }\n\n return current;\n};\n\n// Whether `evaluateLiteral()` and `valueToExpression()` can round-trip the\n// value without losing calls, references, spreads, holes or computed keys.\n// The panel uses it to disable editors, and edits use it as the last check,\n// so both agree on what is editable.\nexport const isLosslesslyEvaluable = (node: t.Node): boolean => {\n const value = unwrapExpression(node);\n\n if (\n t.isStringLiteral(value) ||\n t.isNumericLiteral(value) ||\n t.isBooleanLiteral(value) ||\n t.isNullLiteral(value)\n ) {\n return true;\n }\n\n if (\n t.isUnaryExpression(value) &&\n value.operator === '-' &&\n t.isNumericLiteral(value.argument)\n ) {\n return true;\n }\n\n if (t.isTemplateLiteral(value)) {\n return value.expressions.length === 0;\n }\n\n if (t.isArrayExpression(value)) {\n return value.elements.every(\n element => element !== null && isLosslesslyEvaluable(element),\n );\n }\n\n if (t.isObjectExpression(value)) {\n return value.properties.every(\n property =>\n t.isObjectProperty(property) &&\n !property.computed &&\n (t.isIdentifier(property.key) ||\n t.isStringLiteral(property.key) ||\n t.isNumericLiteral(property.key)) &&\n isLosslesslyEvaluable(property.value),\n );\n }\n\n return false;\n};\n\nexport const canLosslesslyEvaluateSource = (source: string): boolean => {\n try {\n return isLosslesslyEvaluable(\n parseExpression(source, { plugins: ['jsx', 'typescript'] }),\n );\n } catch {\n return false;\n }\n};\n\n// Reads a literal's value from its AST without running any code. Calls,\n// references and other non-literal expressions give `undefined`, so reading\n// a field never executes the document's code.\nexport const evaluateLiteral = (rawNode: t.Node): unknown => {\n const node = unwrapExpression(rawNode);\n\n if (t.isStringLiteral(node)) {\n return node.value;\n }\n\n if (t.isNumericLiteral(node)) {\n return node.value;\n }\n\n if (t.isBooleanLiteral(node)) {\n return node.value;\n }\n\n if (t.isNullLiteral(node)) {\n return null;\n }\n\n if (t.isIdentifier(node) && node.name === 'undefined') {\n return undefined;\n }\n\n if (\n t.isUnaryExpression(node) &&\n node.operator === '-' &&\n t.isNumericLiteral(node.argument)\n ) {\n return -node.argument.value;\n }\n\n if (t.isTemplateLiteral(node) && node.expressions.length === 0) {\n return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw ?? '';\n }\n\n if (t.isJSXElement(node) || t.isJSXFragment(node)) {\n return generateCode(node);\n }\n\n if (t.isArrayExpression(node)) {\n return node.elements.map(element =>\n element ? evaluateLiteral(element) : null,\n );\n }\n\n if (t.isObjectExpression(node)) {\n const result: Record<string, unknown> = {};\n\n for (const prop of node.properties) {\n if (!t.isObjectProperty(prop)) {\n continue;\n }\n\n let key: string | null = null;\n\n if (t.isIdentifier(prop.key)) {\n key = prop.key.name;\n } else if (t.isStringLiteral(prop.key)) {\n key = prop.key.value;\n } else if (t.isNumericLiteral(prop.key)) {\n key = String(prop.key.value);\n }\n\n if (key === null) {\n continue;\n }\n\n result[key] = evaluateLiteral(prop.value);\n }\n\n return result;\n }\n\n return undefined;\n};\n\nexport const parseValue = (value: unknown): unknown => {\n if (typeof value !== 'string') {\n return value;\n }\n\n const trimmed = value.trim();\n\n if (!trimmed) {\n return value;\n }\n\n if (REGEX.NUMBER.test(trimmed)) {\n return parseFloat(trimmed);\n }\n\n if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {\n if (trimmed === 'true') {\n return true;\n }\n if (trimmed === 'false') {\n return false;\n }\n if (trimmed === 'null') {\n return null;\n }\n if (trimmed === 'undefined') {\n return undefined;\n }\n }\n\n if (\n (trimmed.startsWith('{') && trimmed.endsWith('}')) ||\n (trimmed.startsWith('[') && trimmed.endsWith(']'))\n ) {\n try {\n const ast = parseExpression(trimmed, {\n plugins: ['jsx', 'typescript'],\n });\n\n if (t.isObjectExpression(ast) || t.isArrayExpression(ast)) {\n return evaluateLiteral(ast);\n }\n } catch {\n /* Not an object or array literal: keep the string. */\n }\n\n return value;\n }\n\n return value;\n};\n\nexport const extractNodeValue = (node: t.Node): ExtractedNodeValue => {\n if (t.isBooleanLiteral(node)) {\n return { type: 'boolean', value: node.value };\n }\n\n if (t.isNumericLiteral(node)) {\n return { type: 'number', value: node.value };\n }\n\n if (\n t.isUnaryExpression(node) &&\n node.operator === '-' &&\n t.isNumericLiteral(node.argument)\n ) {\n return { type: 'number', value: -node.argument.value };\n }\n\n if (t.isStringLiteral(node)) {\n return { type: 'string', value: node.value };\n }\n\n if (t.isTemplateLiteral(node)) {\n if (node.expressions.length === 0 && node.quasis.length === 1) {\n return {\n type: 'string',\n value: dedent(\n node.quasis[0]!.value.cooked ?? node.quasis[0]!.value.raw,\n ),\n };\n }\n return { type: 'string', value: generateCode(node) };\n }\n\n if (t.isNullLiteral(node)) {\n return { type: 'null', value: null };\n }\n\n if (t.isArrayExpression(node)) {\n return { type: 'array', value: generateCode(node) };\n }\n\n if (t.isObjectExpression(node)) {\n return { type: 'object', value: generateCode(node) };\n }\n\n if (t.isJSXElement(node) || t.isJSXFragment(node)) {\n return { type: 'string', value: generateCode(node) };\n }\n\n return { type: 'unknown', value: null };\n};\n\nexport const parseArrayExpression = (value: string) => {\n try {\n const ast = unwrapExpression(\n parseExpression(value, {\n plugins: ['jsx', 'typescript'],\n }),\n );\n\n if (!t.isArrayExpression(ast)) {\n return null;\n }\n\n return ast;\n } catch (error) {\n console.error('❌ Array parsing error:', error);\n return null;\n }\n};\n\nexport const extractObjectProperties = (\n element: t.ObjectExpression,\n): Record<string, ExtractedNodeValue & { astNode: t.Node }> => {\n const properties: Record<string, ExtractedNodeValue & { astNode: t.Node }> =\n {};\n\n element.properties.forEach(prop => {\n if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {\n const key = prop.key.name;\n\n // `children` and other JSX-valued properties (such as `label`) are\n // edited through `useDndItems`'s nested elements instead (#298).\n if (\n key === 'children' ||\n t.isJSXElement(prop.value) ||\n t.isJSXFragment(prop.value)\n ) {\n return;\n }\n\n const extracted = extractNodeValue(prop.value);\n\n properties[key] = {\n ...extracted,\n astNode: prop.value,\n };\n }\n });\n\n return properties;\n};\n","import { parseExpression } from '@babel/parser';\nimport * as t from '@babel/types';\nimport { z } from 'zod';\n\nimport { BINDING_PROP, DATA_ATTR } from '../../constants';\nimport {\n BINDING_TYPES,\n type BindingItem,\n type BindingKeyMap,\n type BindingOption,\n type BindingOptions,\n type BindingRegistry,\n type BindingRenderLeaf,\n type BindingRenderMap,\n type BindingType,\n type BindingWidget,\n type DataAttrNode,\n} from './types';\nimport { evaluateLiteral, parseArrayExpression, parseValue } from './value';\n\nconst bindingTypeSchema = z.enum(BINDING_TYPES);\n\nconst bindingOptionSchema = z.object({\n label: z.string(),\n value: z.string(),\n});\n\n// `widget.type` is any string, not an enum: the library implements no\n// widgets, so every value belongs to a custom panel (#236). `.passthrough()`\n// keeps that control's own config, such as `{ type: 'slider', snapTo: [...] }`.\nconst bindingWidgetSchema = z\n .object({\n type: z.string().min(1),\n step: z.number().optional(),\n unit: z.string().optional(),\n })\n .passthrough();\n\n// Parses one key on its own. A malformed value becomes absent instead of\n// failing the whole binding, so a typo in `min` loses only `min` (#234).\nconst pick = <T>(schema: z.ZodType<T>, value: unknown): T | undefined => {\n const parsed = schema.safeParse(value);\n\n return parsed.success ? parsed.data : undefined;\n};\n\n// Turns the string form (`widget: 'slider'`) into `{ type }`, so consumers\n// see one shape.\nconst sanitizeWidget = (value: unknown): BindingWidget | undefined => {\n if (typeof value === 'string') {\n return value ? { type: value } : undefined;\n }\n\n return pick(bindingWidgetSchema, value);\n};\n\n// Drops only the malformed options and keeps the valid ones.\nconst sanitizeOptions = (value: unknown): BindingOption[] | undefined => {\n if (!Array.isArray(value)) {\n return undefined;\n }\n\n const options = value.flatMap(option => {\n const parsed = pick(bindingOptionSchema, option);\n\n return parsed ? [parsed] : [];\n });\n\n return options.length > 0 ? options : undefined;\n};\n\n// Every key the library reads from a binding. Any other key is the app's\n// own and goes into `meta`.\nconst KNOWN_BINDING_KEYS = new Set([\n 'label',\n 'property',\n 'type',\n 'widget',\n 'options',\n 'render',\n 'min',\n 'max',\n 'pattern',\n 'required',\n]);\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\n// Sanitizes the fields a binding declares. Shared by top-level bindings and\n// render-map leaves, so a new field reaches both. Absent fields are left\n// off, not set to `undefined`.\nconst sanitizeField = (raw: Record<string, unknown>): BindingRenderLeaf => {\n const metaEntries = Object.entries(raw).filter(\n ([key]) => !KNOWN_BINDING_KEYS.has(key),\n );\n const field: BindingRenderLeaf = {\n label: pick(z.string(), raw.label),\n property: pick(z.string(), raw.property),\n type: pick(bindingTypeSchema, raw.type),\n widget: sanitizeWidget(raw.widget),\n options: sanitizeOptions(raw.options),\n render: sanitizeRenderMap(raw.render),\n min: pick(z.number(), raw.min),\n max: pick(z.number(), raw.max),\n pattern: pick(z.string(), raw.pattern),\n required: pick(z.boolean(), raw.required),\n meta: metaEntries.length > 0 ? Object.fromEntries(metaEntries) : undefined,\n };\n\n return Object.fromEntries(\n Object.entries(field).filter(([, value]) => value !== undefined),\n );\n};\n\n// A render map entry is a leaf (it has `type`) or a nested map. Anything\n// else is dropped, without failing the whole map.\nfunction sanitizeRenderMap(value: unknown): BindingRenderMap | undefined {\n if (!isPlainObject(value)) {\n return undefined;\n }\n\n const map: BindingRenderMap = {};\n\n for (const [key, raw] of Object.entries(value)) {\n if (!isPlainObject(raw)) {\n continue;\n }\n\n if ('type' in raw) {\n // Keep the `type` key even when its value was dropped, so\n // `'type' in leaf` still marks it as a leaf: an unknown type shows as a\n // plain field instead of disappearing (#234).\n map[key] = { type: undefined, ...sanitizeField(raw) };\n continue;\n }\n\n const nested = sanitizeRenderMap(raw);\n\n if (nested) {\n map[key] = nested;\n }\n }\n\n return Object.keys(map).length > 0 ? map : undefined;\n}\n\n// Validates an evaluated `data-binding` array into `BindingItem[]`. Used by\n// `parseBinding` (from a string) and `parseBindingExpression` (from an AST).\nconst buildBindingItems = (raw: unknown): BindingItem[] => {\n if (!Array.isArray(raw)) {\n return [];\n }\n\n return raw.flatMap(rawItem => {\n if (!isPlainObject(rawItem)) {\n return [];\n }\n\n const { label, property, ...field } = sanitizeField(rawItem);\n\n if (label === undefined) {\n return [];\n }\n\n if (property === undefined && field.type !== 'richtext') {\n return [];\n }\n\n return [{ label, property: property ?? BINDING_PROP.INNER_HTML, ...field }];\n });\n};\n\n// Registry entries are validated like an inline `data-binding`. Cached per\n// registry object, which a host defines once rather than every render.\nconst registryEntries = new WeakMap<\n BindingRegistry,\n Map<string, BindingItem[]>\n>();\n\n// Whether a tag name is a component rather than an HTML element, by JSX's\n// own rule: a member path, or an identifier that doesn't start with a\n// lowercase letter. A namespaced name (`svg:rect`) resolves to `''` and is\n// neither.\nexport const isComponentTagName = (tagName: string): boolean =>\n tagName !== '' && (tagName.includes('.') || !/^[a-z]/.test(tagName));\n\n// The bindings `registry` gives an element of `tagName`, or `undefined` when\n// it has no entry for that component. HTML elements never match, even when\n// the registry has a key for them.\nexport const getRegistryBindings = (\n registry: BindingRegistry | undefined,\n tagName: string,\n): BindingItem[] | undefined => {\n if (!registry) {\n return undefined;\n }\n\n let entries = registryEntries.get(registry);\n\n if (!entries) {\n entries = new Map();\n registryEntries.set(registry, entries);\n\n // Once per registry, so a key the type would have rejected doesn't go\n // unnoticed in plain JavaScript or behind a cast.\n const ignored = Object.keys(registry).filter(\n key => !isComponentTagName(key),\n );\n\n if (ignored.length > 0) {\n console.warn(\n `Live.Dnd \\`bindings\\` only applies to components. Ignored: ${ignored.join(', ')}. Bind an HTML element with its own data-binding.`,\n );\n }\n }\n\n if (!isComponentTagName(tagName) || !Object.hasOwn(registry, tagName)) {\n return undefined;\n }\n\n let bindings = entries.get(tagName);\n\n if (!bindings) {\n bindings = buildBindingItems(\n (registry as Record<string, BindingItem[] | undefined>)[tagName],\n );\n entries.set(tagName, bindings);\n }\n\n return bindings;\n};\n\n// Key map entries are validated like inline ones and cached per map, as\n// registry entries are.\nconst keyEntries = new WeakMap<BindingKeyMap, Map<string, BindingItem[]>>();\n\n// Each problem is reported once per key, not on every read of a section.\nconst warnedKeys = new Set<string>();\n\nconst warnOnce = (id: string, message: string) => {\n if (!warnedKeys.has(id)) {\n warnedKeys.add(id);\n console.warn(message);\n }\n};\n\n// The bindings `bindingKeys` has under `key`, or `undefined` when it has no\n// such entry.\nexport const getKeyBindings = (\n bindingKeys: BindingKeyMap | undefined,\n key: string,\n): BindingItem[] | undefined => {\n if (!bindingKeys || !Object.hasOwn(bindingKeys, key)) {\n return undefined;\n }\n\n let entries = keyEntries.get(bindingKeys);\n\n if (!entries) {\n entries = new Map();\n keyEntries.set(bindingKeys, entries);\n }\n\n let bindings = entries.get(key);\n\n if (!bindings) {\n bindings = buildBindingItems(bindingKeys[key]);\n entries.set(key, bindings);\n }\n\n return bindings;\n};\n\n// One element's bindings, from the most specific source it has (#513):\n//\n// 1. `own`, its `data-binding`, parsed. `undefined` when it has none; an\n// empty array is still its own, which is how an element opts out.\n// 2. `key`, the string its `data-binding-key` names in `bindingKeys`.\n// `undefined` without the attribute, `null` when the attribute isn't a\n// plain string. A key with no entry gives no fields rather than falling\n// through to the registry.\n// 3. Its component's entry in `bindings`.\nexport const resolveBindings = (\n own: BindingItem[] | undefined,\n key: string | null | undefined,\n tagName: string,\n options: BindingOptions = {},\n): BindingItem[] => {\n if (own) {\n if (key !== undefined) {\n warnOnce(\n `both:${key}`,\n `Live.Dnd: an element has both data-binding and data-binding-key=\"${key ?? ''}\". Its data-binding is used; remove one of them.`,\n );\n }\n\n return own;\n }\n\n if (key === null) {\n warnOnce(\n 'not-a-string',\n 'Live.Dnd: data-binding-key must be a plain string, such as data-binding-key=\"hero-title\". The element has no fields.',\n );\n\n return [];\n }\n\n if (key !== undefined) {\n const bindings = getKeyBindings(options.bindingKeys, key);\n\n if (!bindings) {\n warnOnce(\n `missing:${key}`,\n `Live.Dnd: data-binding-key=\"${key}\" isn't in bindingKeys. The element has no fields.`,\n );\n }\n\n return bindings ?? [];\n }\n\n return getRegistryBindings(options.bindings, tagName) ?? [];\n};\n\nexport const parseBinding = (bindingValue: string | null): BindingItem[] => {\n if (!bindingValue) {\n return [];\n }\n\n const ast = parseArrayExpression(bindingValue);\n\n if (!ast) {\n return [];\n }\n\n return buildBindingItems(evaluateLiteral(ast));\n};\n\n// `parseBinding` for an array expression that is already parsed, as\n// `extract` has it. Saves printing it and parsing it again (#241).\nexport const parseBindingExpression = (\n expression: t.ArrayExpression,\n): BindingItem[] => buildBindingItems(evaluateLiteral(expression));\n\nexport const getCurrentValue = (\n node: DataAttrNode,\n property: string,\n): string => {\n switch (property) {\n case BINDING_PROP.INNER_TEXT: {\n return node.textContent || '';\n }\n\n case BINDING_PROP.INNER_HTML: {\n // A `richtext` value lives in `dangerouslySetInnerHTML={{ __html }}`.\n const dsiAttr = node.attributes.find(\n a => a.name === 'dangerouslySetInnerHTML',\n );\n if (dsiAttr?.value) {\n try {\n const expr = parseExpression(dsiAttr.value, {\n plugins: ['jsx', 'typescript'],\n });\n if (t.isObjectExpression(expr)) {\n const htmlProp = expr.properties.find(\n p =>\n t.isObjectProperty(p) &&\n t.isIdentifier(p.key) &&\n p.key.name === '__html',\n ) as t.ObjectProperty | undefined;\n if (htmlProp) {\n if (t.isStringLiteral(htmlProp.value)) {\n return htmlProp.value.value;\n }\n if (\n t.isTemplateLiteral(htmlProp.value) &&\n htmlProp.value.expressions.length === 0\n ) {\n return (\n htmlProp.value.quasis[0]?.value.cooked ??\n htmlProp.value.quasis[0]?.value.raw ??\n ''\n );\n }\n }\n }\n } catch {\n // Not a readable object: fall back to the children below.\n }\n }\n return node.rawChildren || node.textContent || '';\n }\n\n case BINDING_PROP.CHILDREN: {\n return JSON.stringify(node?.children || []);\n }\n\n default: {\n const customAttr = node.attributes.find(attr => attr.name === property);\n const value = customAttr?.value || '';\n\n return value;\n }\n }\n};\n\n// Types whose value stays a string, even when the text looks like a number\n// or an object. `jsx` and `richtext` hold source code, which `update` writes\n// back as an expression.\nexport const STRING_VALUED_TYPES: ReadonlySet<BindingType> = new Set([\n 'string',\n 'url',\n 'date',\n 'color',\n 'jsx',\n 'richtext',\n]);\n\n// The value as its JS type (number, boolean, object, array or string), for\n// `PanelBinding.value`. `getCurrentValue` gives the source text, for\n// `PanelBinding.rawValue` (#238). A string literal in the source stays a\n// string whatever it contains; only expressions such as `count={3}` or\n// `data={[...]}` are read into their real shape.\nexport const getStructuredValue = (\n node: DataAttrNode,\n property: string,\n type?: BindingType,\n): unknown => {\n switch (property) {\n case BINDING_PROP.INNER_TEXT:\n case BINDING_PROP.INNER_HTML: {\n return getCurrentValue(node, property);\n }\n\n case BINDING_PROP.CHILDREN: {\n return node.children ?? [];\n }\n\n default: {\n const raw = getCurrentValue(node, property);\n const attr = node.attributes.find(a => a.name === property);\n\n if (attr?.isStringLiteral || (type && STRING_VALUED_TYPES.has(type))) {\n return raw;\n }\n\n return parseValue(raw);\n }\n }\n};\n\n// The node's bindings. `extract()` resolves them from all three sources\n// (#509, #513); a node built some other way may only have its\n// `data-binding` attribute, which is parsed here.\nexport const readNodeBindings = (node: DataAttrNode): BindingItem[] => {\n if (node.bindings) {\n return node.bindings;\n }\n\n const bindingAttr = node.dataAttributes.find(\n attr => attr.name === DATA_ATTR.BINDING,\n );\n\n return bindingAttr?.value ? parseBinding(bindingAttr.value) : [];\n};\n\nconst hasEditableBindings = (node: DataAttrNode): boolean =>\n readNodeBindings(node).length > 0;\n\nexport const findEditableChildren = (node: DataAttrNode): DataAttrNode[] => {\n const editableChildren: DataAttrNode[] = [];\n\n const traverse = (children: DataAttrNode[] | undefined) => {\n if (!children) {\n return;\n }\n\n for (const child of children) {\n if (hasEditableBindings(child)) {\n editableChildren.push(child);\n }\n traverse(child.children);\n }\n };\n\n traverse(node.children);\n\n return editableChildren;\n};\n","import { parse } from '@babel/parser';\nimport * as t from '@babel/types';\nimport { nanoid } from 'nanoid';\n\nimport { BINDING_PROP, CONFIG, DATA_ATTR } from '../../constants';\nimport { type BoundedCache, createBoundedCache } from '../cache';\nimport { registerEditorCache } from '../editor-caches';\nimport {\n parseBinding,\n parseBindingExpression,\n resolveBindings,\n} from './binding';\nimport { traverse } from './document';\nimport { attrValue, generateCode, wrap } from './helpers';\nimport { getJSXTagName } from './jsx-name';\nimport type {\n Attribute,\n BindingItem,\n BindingOptions,\n DataAttrNode,\n} from './types';\nimport { unwrapExpression } from './value';\n\nconst collectText = (\n children: (\n | t.JSXText\n | t.JSXExpressionContainer\n | t.JSXElement\n | t.JSXFragment\n | t.JSXSpreadChild\n )[],\n) => {\n return children\n .filter(c => t.isJSXText(c))\n .map(c => (c as t.JSXText).value.trim())\n .filter(v => v.length)\n .join(' ');\n};\n\nconst parseJSXName = (\n tagName: string,\n): t.JSXIdentifier | t.JSXMemberExpression => {\n const parts = tagName.split('.');\n\n if (parts.length === 1) {\n return t.jsxIdentifier(parts[0]!);\n }\n\n let expr: t.JSXIdentifier | t.JSXMemberExpression = t.jsxIdentifier(\n parts[0]!,\n );\n\n for (let i = 1; i < parts.length; i++) {\n expr = t.jsxMemberExpression(expr, t.jsxIdentifier(parts[i]!));\n }\n\n return expr;\n};\n\nconst extractCache = createBoundedCache<string, DataAttrNode[]>(\n CONFIG.CACHE_LIMIT,\n);\n\n// One cache per combination of `bindings` and `bindingKeys`, since they\n// change what the same source extracts to (#509, #513). An absent map is\n// keyed by `NO_MAP`.\nconst NO_MAP = {};\nlet optionExtractCaches = new WeakMap<\n object,\n WeakMap<object, BoundedCache<string, DataAttrNode[]>>\n>();\n\nconst cacheFor = ({ bindings, bindingKeys }: BindingOptions) => {\n if (!bindings && !bindingKeys) {\n return extractCache;\n }\n\n let byKeys = optionExtractCaches.get(bindings ?? NO_MAP);\n\n if (!byKeys) {\n byKeys = new WeakMap();\n optionExtractCaches.set(bindings ?? NO_MAP, byKeys);\n }\n\n let cache = byKeys.get(bindingKeys ?? NO_MAP);\n\n if (!cache) {\n cache = createBoundedCache<string, DataAttrNode[]>(CONFIG.CACHE_LIMIT);\n byKeys.set(bindingKeys ?? NO_MAP, cache);\n }\n\n return cache;\n};\n\nconst extractAttributes = (\n attributes: (t.JSXAttribute | t.JSXSpreadAttribute)[],\n source?: string,\n): { allAttrs: Attribute[]; dataAttrs: Attribute[] } => {\n const allAttrs: Attribute[] = [];\n const dataAttrs: Attribute[] = [];\n\n for (const attr of attributes) {\n if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {\n continue;\n }\n\n const name = attr.name.name;\n let value: string | null = null;\n let isStringLiteral = false;\n\n if (attr.value) {\n if (t.isStringLiteral(attr.value)) {\n value = attr.value.value;\n isStringLiteral = true;\n } else if (t.isJSXExpressionContainer(attr.value)) {\n try {\n const expression = attr.value.expression;\n const structural =\n t.isArrayExpression(unwrapExpression(expression)) ||\n t.isObjectExpression(unwrapExpression(expression));\n value =\n source &&\n structural &&\n expression.start != null &&\n expression.end != null\n ? source.slice(expression.start, expression.end)\n : generateCode(expression);\n isStringLiteral = false;\n } catch {\n value = null;\n }\n }\n }\n\n const entry = { name, value, isStringLiteral };\n\n allAttrs.push(entry);\n\n if (name.startsWith('data-')) {\n dataAttrs.push(entry);\n }\n }\n\n return { allAttrs, dataAttrs };\n};\n\nconst buildChildElements = (\n node: DataAttrNode,\n): (t.JSXText | t.JSXElement | t.JSXFragment)[] => {\n const childElements: (t.JSXText | t.JSXElement | t.JSXFragment)[] = [];\n\n if (node.textContent) {\n childElements.push(t.jsxText(node.textContent));\n }\n\n node.children?.forEach(child => {\n const childJSX = nodeToJSX(child);\n if (childJSX) {\n childElements.push(childJSX);\n }\n });\n\n return childElements;\n};\n\nexport const nodeToJSX = (\n node: DataAttrNode,\n): t.JSXElement | t.JSXFragment | null => {\n try {\n if (node.isFragment) {\n const childElements = buildChildElements(node);\n\n return t.jsxFragment(\n t.jsxOpeningFragment(),\n t.jsxClosingFragment(),\n childElements,\n );\n }\n\n if (\n node.tagName === 'div' &&\n node.dataAttributes.some(attr => attr.name === 'data-item')\n ) {\n if (node.children) {\n return nodeToJSX(node.children[0]!);\n }\n return null;\n }\n\n const attributes = node.attributes.map(attr => {\n const attrName = t.jsxIdentifier(attr.name);\n\n if (!attr.value) {\n return t.jsxAttribute(attrName, null);\n }\n\n return t.jsxAttribute(attrName, attrValue(attr));\n });\n\n const elementName = parseJSXName(node.tagName);\n\n const openingElement = t.jsxOpeningElement(elementName, attributes);\n\n const closingElement = t.jsxClosingElement(elementName);\n const children = buildChildElements(node);\n\n return t.jsxElement(openingElement, closingElement, children, false);\n } catch (error) {\n console.error('❌ DataAttrNode to JSX conversion error:', error);\n return null;\n }\n};\n\nconst createWrapperNode = (\n textContent: string,\n children: DataAttrNode[],\n): DataAttrNode => ({\n tagName: 'div',\n id: nanoid(6),\n attributes: [{ name: DATA_ATTR.ITEM, value: 'true' }],\n dataAttributes: [{ name: DATA_ATTR.ITEM, value: 'true' }],\n textContent,\n children,\n});\n\nconst createFragmentNode = (\n textContent: string,\n children: DataAttrNode[],\n): DataAttrNode => ({\n tagName: '',\n id: nanoid(6),\n attributes: [],\n dataAttributes: [],\n textContent,\n children,\n isFragment: true,\n});\n\nconst processChildrenBinding = (\n jsxElement: t.JSXElement,\n processedNodes?: WeakSet<t.JSXElement | t.JSXFragment>,\n shouldWrap: boolean = true,\n source?: string,\n options?: BindingOptions,\n): DataAttrNode[] | undefined => {\n const jsxChildren = jsxElement.children.filter(\n child => t.isJSXElement(child) || t.isJSXFragment(child),\n );\n\n if (!jsxChildren.length) {\n return undefined;\n }\n\n const childrenNodes: DataAttrNode[] = [];\n\n jsxChildren.forEach(child => {\n if (t.isJSXElement(child)) {\n const childResults = extractFromNode(\n child,\n processedNodes,\n source,\n options,\n );\n\n if (shouldWrap) {\n const wrapperNode = createWrapperNode(\n collectText(child.children),\n childResults,\n );\n wrapperNode.source = source?.slice(child.start!, child.end!);\n const dataId = childResults[0]?.dataAttributes.find(\n attr => attr.name === DATA_ATTR.ID,\n )?.value;\n\n if (dataId) {\n wrapperNode.id = `child:${dataId}`;\n }\n\n childrenNodes.push(wrapperNode);\n } else {\n childrenNodes.push(...childResults);\n }\n } else if (t.isJSXFragment(child)) {\n processedNodes?.add(child);\n\n const fragmentChildren: DataAttrNode[] = [];\n\n child.children.forEach(fragmentChild => {\n if (t.isJSXElement(fragmentChild)) {\n const childResults = extractFromNode(\n fragmentChild,\n processedNodes,\n source,\n options,\n );\n fragmentChildren.push(...childResults);\n }\n });\n\n if (fragmentChildren.length) {\n const fragmentNode = createFragmentNode(\n collectText(child.children),\n fragmentChildren,\n );\n fragmentNode.source = source?.slice(child.start!, child.end!);\n childrenNodes.push(fragmentNode);\n }\n }\n });\n\n return childrenNodes.length ? childrenNodes : undefined;\n};\n\nconst skipItemsChildren = (\n jsxElement: t.JSXElement,\n processedNodes: WeakSet<t.JSXElement | t.JSXFragment>,\n propertyName: string = 'items',\n): void => {\n const opening = jsxElement.openingElement;\n\n const itemsAttr = opening.attributes.find(\n attr =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === propertyName,\n );\n\n if (!itemsAttr || !t.isJSXAttribute(itemsAttr)) {\n return;\n }\n\n if (\n itemsAttr.value &&\n t.isJSXExpressionContainer(itemsAttr.value) &&\n t.isArrayExpression(itemsAttr.value.expression)\n ) {\n const arrayExpr = itemsAttr.value.expression;\n\n arrayExpr.elements.forEach(element => {\n if (t.isObjectExpression(element)) {\n element.properties.forEach(prop => {\n if (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key) &&\n t.isJSXElement(prop.value)\n ) {\n markProcessedJSX(prop.value, processedNodes);\n }\n });\n }\n });\n }\n};\n\nconst markProcessedJSX = (\n node: t.Node,\n processedNodes: WeakSet<t.JSXElement | t.JSXFragment>,\n): void => {\n if (t.isJSXElement(node) || t.isJSXFragment(node)) {\n processedNodes.add(node as t.JSXElement | t.JSXFragment);\n node.children.forEach(child => markProcessedJSX(child, processedNodes));\n return;\n }\n\n const expression =\n t.isJSXExpressionContainer(node) || t.isParenthesizedExpression(node);\n\n if (expression) {\n markProcessedJSX(node.expression, processedNodes);\n }\n};\n\ninterface NodeBindingInfo {\n tagName: string;\n allAttrs: Attribute[];\n dataAttrs: Attribute[];\n bindings: BindingItem[];\n childrenBinding: BindingItem | undefined;\n arrayBindings: BindingItem[];\n rawChildren: string | undefined;\n}\n\n// The `data-binding` array expression, so bindings can be read from the AST\n// without printing and parsing it again. `null` when the attribute is\n// missing or a plain string, which goes through `parseBinding` instead.\nconst getBindingExpression = (\n opening: t.JSXOpeningElement,\n): t.ArrayExpression | null => {\n for (const attr of opening.attributes) {\n if (\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === DATA_ATTR.BINDING &&\n attr.value &&\n t.isJSXExpressionContainer(attr.value)\n ) {\n // Unwrap `satisfies BindingItem[]`, `as const` and parentheses.\n const expression = unwrapExpression(attr.value.expression);\n\n if (t.isArrayExpression(expression)) {\n return expression;\n }\n }\n }\n\n return null;\n};\n\n// Reads one element's tag name, attributes and bindings. Shared by the\n// top-level visitor in `parseToNodes` and by `extractFromNode`.\nconst readNodeBindingInfo = (\n node: t.JSXElement,\n source?: string,\n options?: BindingOptions,\n): NodeBindingInfo => {\n const opening = node.openingElement;\n const tagName = getJSXTagName(opening);\n const { allAttrs, dataAttrs } = extractAttributes(opening.attributes, source);\n\n const bindingAttr = dataAttrs.find(attr => attr.name === DATA_ATTR.BINDING);\n const bindingExpr = getBindingExpression(opening);\n const keyAttr = dataAttrs.find(attr => attr.name === DATA_ATTR.BINDING_KEY);\n // Its own `data-binding` first, even an empty one (how an element opts\n // out), then its `data-binding-key`, then its component's entry\n // (#509, #513).\n const bindings = resolveBindings(\n bindingExpr\n ? parseBindingExpression(bindingExpr)\n : bindingAttr\n ? parseBinding(bindingAttr.value)\n : undefined,\n keyAttr && (keyAttr.isStringLiteral ? keyAttr.value : null),\n tagName,\n options,\n );\n\n const childrenBinding = bindings.find(\n b => b.property === BINDING_PROP.CHILDREN,\n );\n const arrayBindings = bindings.filter(\n b => b.property === BINDING_PROP.ITEMS || b.type === 'array',\n );\n\n const innerHtmlBinding = bindings.find(\n b => b.property === BINDING_PROP.INNER_HTML,\n );\n\n let rawChildren: string | undefined;\n if (innerHtmlBinding && node.children.length > 0) {\n rawChildren = node.children\n .map(child => generateCode(child))\n .join('')\n .trim();\n }\n\n return {\n tagName,\n allAttrs,\n dataAttrs,\n bindings,\n childrenBinding,\n arrayBindings,\n rawChildren,\n };\n};\n\nconst parseToNodes = (\n raw: string,\n options?: BindingOptions,\n): DataAttrNode[] => {\n const wrapped = wrap(raw);\n const ast = parse(wrapped, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n errorRecovery: true,\n });\n\n const results: DataAttrNode[] = [];\n\n // Elements already recorded as another result's children, or skipped\n // inside an `items` array. `traverse()` visits every element, so the\n // visitor skips these to avoid recording them twice.\n const processedNodes = new WeakSet<t.JSXElement | t.JSXFragment>();\n\n traverse(ast, {\n JSXElement(path) {\n if (processedNodes.has(path.node)) {\n return;\n }\n\n const {\n tagName,\n allAttrs,\n dataAttrs,\n bindings,\n childrenBinding,\n arrayBindings,\n rawChildren,\n } = readNodeBindingInfo(path.node, wrapped, options);\n\n if (!tagName || !dataAttrs.length) {\n return;\n }\n\n let childrenNodes: DataAttrNode[] | undefined;\n\n if (childrenBinding) {\n childrenNodes = processChildrenBinding(\n path.node,\n processedNodes,\n true,\n wrapped,\n options,\n );\n }\n\n for (const arrayBinding of arrayBindings) {\n skipItemsChildren(path.node, processedNodes, arrayBinding.property);\n }\n\n results.push({\n tagName,\n attributes: allAttrs,\n dataAttributes: dataAttrs,\n textContent: collectText(path.node.children),\n rawChildren,\n children: childrenNodes,\n bindings,\n loc: path.node.loc\n ? {\n start: {\n line: path.node.loc.start.line,\n column: path.node.loc.start.column,\n },\n end: {\n line: path.node.loc.end.line,\n column: path.node.loc.end.column,\n },\n }\n : undefined,\n });\n },\n });\n\n return results;\n};\n\n// The elements of `raw` that carry `data-*` attributes, with their\n// bindings, as `DataAttrNode`s. Cached. `options` supplies bindings for\n// elements without their own `data-binding` (#509, #513).\nexport function extract(\n raw: string,\n options: BindingOptions = {},\n): DataAttrNode[] {\n const cache = cacheFor(options);\n\n if (cache.has(raw)) {\n return cache.get(raw)!;\n }\n\n const results = parseToNodes(raw, options);\n\n cache.set(raw, results);\n\n return results;\n}\n\nfunction extractFromNode(\n node: t.JSXElement,\n processedNodes?: WeakSet<t.JSXElement | t.JSXFragment>,\n source?: string,\n options?: BindingOptions,\n): DataAttrNode[] {\n processedNodes?.add(node);\n\n const {\n tagName,\n allAttrs,\n dataAttrs,\n bindings,\n childrenBinding,\n rawChildren,\n } = readNodeBindingInfo(node, source, options);\n\n let childrenNodes: DataAttrNode[] | undefined;\n\n if (childrenBinding) {\n childrenNodes = processChildrenBinding(\n node,\n processedNodes,\n true,\n source,\n options,\n );\n }\n\n if (!childrenNodes) {\n childrenNodes = processChildrenBinding(\n node,\n processedNodes,\n false,\n source,\n options,\n );\n }\n\n return [\n {\n tagName,\n attributes: allAttrs,\n dataAttributes: dataAttrs,\n textContent: collectText(node.children),\n rawChildren,\n children: childrenNodes,\n bindings,\n },\n ];\n}\n\nexport function clearExtractCache() {\n extractCache.clear();\n optionExtractCaches = new WeakMap();\n}\n\nregisterEditorCache(clearExtractCache);\n","export const removeIndices = <T>(items: T[], indices: Set<number>): T[] => {\n return items.filter((_, index) => !indices.has(index));\n};\n\n/**\n * Shifts every selected index up/down by one step as a block, preserving\n * relative order — scattered selections stop moving individually once they\n * hit an unselected neighbor, so the whole group slides together instead of\n * items passing through each other.\n */\nexport const moveSelectedIndices = <T>(\n items: T[],\n indices: Set<number>,\n direction: 'up' | 'down',\n): { items: T[]; indices: Set<number> } => {\n const next = [...items];\n const nextIndices = new Set(indices);\n\n const ordered = [...indices].sort((a, b) =>\n direction === 'up' ? a - b : b - a,\n );\n\n for (const index of ordered) {\n const target = direction === 'up' ? index - 1 : index + 1;\n\n if (target < 0 || target >= next.length || nextIndices.has(target)) {\n continue;\n }\n\n [next[index], next[target]] = [next[target]!, next[index]!];\n nextIndices.delete(index);\n nextIndices.add(target);\n }\n\n return { items: next, indices: nextIndices };\n};\n","// Applies source edits by position: the spans `update` records are\n// replaced, and everything else is copied as is, so an edit never reformats\n// code it didn't touch (#239). Not `magic-string`, which would become a\n// runtime dependency for features (source maps, moves) this doesn't need.\nexport interface SourceEdit {\n start: number;\n end: number;\n content: string;\n // Indent `content`'s later lines to match the line it lands on. Only for\n // generated code, which is printed from column zero; a value the author\n // wrote must go in exactly as written. Applied only when every newline is\n // layout (`hasOnlyLayoutNewlines`).\n indent?: boolean;\n}\n\n// Whether every newline in generated code is layout, not part of a value.\n// Babel escapes newlines in ordinary strings, so a meaningful newline can\n// only come from a template literal or JSX text, which start with a\n// backtick or `<`. Indenting such a newline would change the value, again\n// on every edit.\n//\n// Anything ambiguous returns false: a missed indent is harmless, a changed\n// value is not.\nconst hasOnlyLayoutNewlines = (content: string): boolean => {\n let index = 0;\n\n while (index < content.length) {\n const char = content[index];\n\n // `<` also matches comparison operators and TS generics. Refusing those\n // is harmless.\n if (char === '`' || char === '<') {\n return false;\n }\n\n if (char === '\"' || char === \"'\") {\n const next = skipStringLiteral(content, index);\n\n if (next === -1) {\n return false;\n }\n\n index = next;\n continue;\n }\n\n if (char === '/') {\n const following = content[index + 1];\n\n if (following === '/') {\n const lineEnd = content.indexOf('\\n', index + 2);\n index = lineEnd === -1 ? content.length : lineEnd;\n continue;\n }\n\n if (following === '*') {\n const commentEnd = content.indexOf('*/', index + 2);\n\n if (commentEnd === -1) {\n return false;\n }\n\n index = commentEnd + 2;\n continue;\n }\n\n // Division or a regex literal — indistinguishable without parsing.\n return false;\n }\n\n index++;\n }\n\n return true;\n};\n\n// The index just past the closing quote, or -1 when the literal doesn't end\n// on its line. Generated JS never has a bare newline in a string, so one\n// means the scan is lost.\nconst skipStringLiteral = (content: string, start: number): number => {\n const quote = content[start];\n\n for (let index = start + 1; index < content.length; index++) {\n const char = content[index];\n\n if (char === '\\\\') {\n // A backslash before a newline is a line continuation, so the newline\n // is part of the string's source. Indenting it would change the\n // string: give up.\n const escaped = content[index + 1];\n\n if (escaped === '\\n' || escaped === '\\r') {\n return -1;\n }\n\n index++;\n continue;\n }\n\n if (char === quote) {\n return index + 1;\n }\n\n if (char === '\\n') {\n return -1;\n }\n }\n\n return -1;\n};\n\n// Indentation of the line that `offset` falls on.\nconst lineIndentAt = (source: string, offset: number): string => {\n const lineStart = source.lastIndexOf('\\n', offset - 1) + 1;\n const match = /^[ \\t]*/.exec(source.slice(lineStart, offset));\n\n return match?.[0] ?? '';\n};\n\n// The file's own line ending, so generated code (always LF from Babel)\n// doesn't mix endings in a CRLF file. Used only with re-indentation.\nconst lineTerminatorOf = (source: string): string => {\n return source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n};\n\n// Applies non-overlapping edits to `source` in one pass. An edit with\n// `start === end` inserts. Throws on overlapping or out-of-range edits,\n// which mean the caller's offsets are wrong, instead of returning broken\n// source.\nexport const applyEdits = (source: string, edits: SourceEdit[]): string => {\n if (edits.length === 0) {\n return source;\n }\n\n const ordered = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);\n\n for (const edit of ordered) {\n if (\n !Number.isInteger(edit.start) ||\n !Number.isInteger(edit.end) ||\n edit.start < 0 ||\n edit.end > source.length ||\n edit.start > edit.end\n ) {\n throw new Error(\n `Invalid source edit [${edit.start}, ${edit.end}) for a source of length ${source.length}`,\n );\n }\n }\n\n for (let i = 1; i < ordered.length; i++) {\n const previous = ordered[i - 1]!;\n const current = ordered[i]!;\n\n if (current.start < previous.end) {\n throw new Error(\n `Overlapping source edits: [${previous.start}, ${previous.end}) and [${current.start}, ${current.end})`,\n );\n }\n }\n\n let result = '';\n let cursor = 0;\n const terminator = lineTerminatorOf(source);\n\n for (const edit of ordered) {\n const content =\n edit.indent &&\n edit.content.includes('\\n') &&\n hasOnlyLayoutNewlines(edit.content)\n ? edit.content.replace(\n /\\n/g,\n `${terminator}${lineIndentAt(source, edit.start)}`,\n )\n : edit.content;\n\n result += source.slice(cursor, edit.start) + content;\n cursor = edit.end;\n }\n\n return result + source.slice(cursor);\n};\n","import { parseExpression } from '@babel/parser';\nimport * as t from '@babel/types';\nimport { nanoid } from 'nanoid';\n\nimport { moveSelectedIndices } from '../selection';\nimport { extract, nodeToJSX } from './extract';\nimport { generateCode } from './helpers';\nimport { type SourceEdit, applyEdits } from './patch';\nimport type { BindingOptions, DataAttrNode } from './types';\n\nexport type ChildrenAction =\n | { type: 'move'; from: number; to: number }\n | { type: 'move-selected'; indices: number[]; direction: 'up' | 'down' }\n | { type: 'remove' | 'duplicate'; indices: number[] }\n | { type: 'append' };\n\nexport interface ChildrenEdit {\n kind: 'children-edit';\n expected: string[];\n action: ChildrenAction;\n}\n\n// Signatures address the extracted list, not synthetic wrapper IDs. The\n// source editor checks them against the latest parent before using indices.\nconst modeledSignatures = (nodes: DataAttrNode[]): string[] =>\n nodes.map(node => {\n const jsx = nodeToJSX(node);\n\n if (!jsx) {\n throw new Error('Invalid child node');\n }\n\n return generateCode(jsx);\n });\n\nexport const getChildrenSignatures = (nodes: DataAttrNode[]): string[] => {\n const modeled = modeledSignatures(nodes);\n\n return nodes.map((node, index) =>\n JSON.stringify([node.source ?? null, modeled[index]]),\n );\n};\n\nconst indicesAreValid = (\n indices: unknown,\n count: number,\n): indices is number[] =>\n Array.isArray(indices) &&\n new Set(indices).size === indices.length &&\n indices.every(\n index => Number.isInteger(index) && index >= 0 && index < count,\n );\n\n// Only ID attributes are replaced: expressions, spreads, comments and text\n// in a copied subtree retain their exact source. Dynamic IDs are ambiguous.\nconst copySource = (source: string, usedIds: Set<string>): string => {\n const node = parseExpression(source, { plugins: ['jsx', 'typescript'] });\n const edits: SourceEdit[] = [];\n const newId = () => {\n let id = nanoid(12);\n\n while (usedIds.has(id)) {\n id = nanoid(12);\n }\n\n usedIds.add(id);\n\n return id;\n };\n\n t.traverseFast(node, child => {\n if (!t.isJSXOpeningElement(child)) {\n return;\n }\n\n const ids = child.attributes.filter(\n (attr): attr is t.JSXAttribute =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name, { name: 'data-id' }),\n );\n\n if (ids.length > 1) {\n throw new Error('Duplicate data-id attributes');\n }\n\n const attr = ids[0];\n\n if (\n attr &&\n child.attributes\n .slice(child.attributes.indexOf(attr) + 1)\n .some(attribute => t.isJSXSpreadAttribute(attribute))\n ) {\n throw new Error('A spread may override the copied data-id');\n }\n\n if (attr) {\n const value = attr.value;\n\n if (\n !t.isStringLiteral(value) ||\n value.start == null ||\n value.end == null\n ) {\n throw new Error('Cannot copy a dynamic data-id');\n }\n\n edits.push({\n start: value.start,\n end: value.end,\n content: JSON.stringify(newId()),\n });\n } else {\n const at = child.attributes.at(-1)?.end ?? child.name.end;\n\n if (at == null) {\n throw new Error('Missing opening element span');\n }\n\n edits.push({\n start: at,\n end: at,\n content: ` data-id=\"${newId()}\"`,\n });\n }\n });\n\n return applyEdits(source, edits);\n};\n\n// Coordinates refer to the caller's wrapped source, just like other update\n// editors. Non-element gaps stay at their original positions; moving a JSX\n// child moves its entire subtree but never regenerates intervening content.\nexport const editChildrenSource = (\n source: string,\n parent: t.JSXElement,\n input: unknown,\n // The binding sources the caller extracted the children with, so they're\n // modeled the same way here (#509, #513).\n options?: BindingOptions,\n): SourceEdit[] | null => {\n try {\n if (!parent.closingElement || parent.start == null || parent.end == null) {\n return null;\n }\n\n const value = typeof input === 'string' ? JSON.parse(input) : input;\n const children = parent.children.filter(\n (child): child is t.JSXElement | t.JSXFragment =>\n t.isJSXElement(child) || t.isJSXFragment(child),\n );\n const raw = children.map(child => source.slice(child.start!, child.end!));\n const models =\n extract(source.slice(parent.start, parent.end), options)[0]?.children ??\n [];\n\n // The extractor currently omits some empty/expression-only fragments.\n // Never interpret its visible indices as different source children.\n if (models.length !== children.length) {\n return null;\n }\n\n const signatures = modeledSignatures(models);\n const replaceSlots = (next: string[]): SourceEdit[] => {\n const edits = children.map((child, index) => ({\n start: child.start!,\n end: child.end!,\n content: next[index] ?? '',\n }));\n\n if (next.length > children.length) {\n const at = parent.closingElement!.start!;\n edits.push({\n start: at,\n end: at,\n content: next.slice(children.length).join(''),\n });\n }\n\n return edits;\n };\n\n if (Array.isArray(value)) {\n // A full list of children (the JSON form). Unchanged children keep\n // their original source; other replacements are allowed only when\n // every original child can be represented without loss.\n const desired = modeledSignatures(value);\n const lossless = raw.every(\n (text, index) =>\n generateCode(\n parseExpression(text, { plugins: ['jsx', 'typescript'] }),\n ) === signatures[index],\n );\n const consumed = new Set<number>();\n const next = desired.map((signature, position) => {\n const index = signatures.findIndex(\n (candidate, i) =>\n candidate === signature &&\n !consumed.has(i) &&\n (value[position].source === undefined ||\n value[position].source === raw[i]),\n );\n\n if (index >= 0) {\n consumed.add(index);\n\n return raw[index]!;\n }\n\n if (\n !lossless ||\n (value[position].source !== undefined &&\n !raw.includes(value[position].source))\n ) {\n throw new Error(\n 'Use children commands to copy or edit unsupported source',\n );\n }\n\n return signature;\n });\n\n // The list may contain new children. Refuse a repeated `data-id`,\n // which would make later edits ambiguous.\n const countIds = (text: string) => {\n const counts = new Map<string, number>();\n t.traverseFast(\n parseExpression(text, { plugins: ['jsx', 'typescript'] }),\n node => {\n if (\n t.isJSXAttribute(node) &&\n t.isJSXIdentifier(node.name, { name: 'data-id' }) &&\n t.isStringLiteral(node.value)\n ) {\n counts.set(\n node.value.value,\n (counts.get(node.value.value) ?? 0) + 1,\n );\n }\n },\n );\n\n return counts;\n };\n const previousIds = countIds(source);\n const updatedParent = applyEdits(source, replaceSlots(next));\n const nextIds = countIds(updatedParent);\n\n if (\n [...nextIds].some(\n ([id, count]) => count > 1 && count > (previousIds.get(id) ?? 0),\n )\n ) {\n return null;\n }\n\n return replaceSlots(next);\n }\n\n const request = value as ChildrenEdit | null;\n\n if (\n request?.kind !== 'children-edit' ||\n !Array.isArray(request.expected) ||\n request.expected.length !== signatures.length ||\n !getChildrenSignatures(models).every(\n (signature, index) => signature === request.expected[index],\n ) ||\n !request.action\n ) {\n return null;\n }\n\n const { action } = request;\n const usedIds = new Set<string>();\n\n t.traverseFast(parent, node => {\n if (\n t.isJSXAttribute(node) &&\n t.isJSXIdentifier(node.name, { name: 'data-id' }) &&\n t.isStringLiteral(node.value)\n ) {\n usedIds.add(node.value.value);\n }\n });\n\n switch (action.type) {\n case 'move': {\n if (\n !indicesAreValid([action.from], raw.length) ||\n !indicesAreValid([action.to], raw.length)\n ) {\n return null;\n }\n\n const next = [...raw];\n const [moved] = next.splice(action.from, 1);\n next.splice(action.to, 0, moved!);\n\n return replaceSlots(next);\n }\n case 'move-selected': {\n if (\n !indicesAreValid(action.indices, raw.length) ||\n !['up', 'down'].includes(action.direction)\n ) {\n return null;\n }\n\n return replaceSlots(\n moveSelectedIndices(raw, new Set(action.indices), action.direction)\n .items,\n );\n }\n case 'remove': {\n if (!indicesAreValid(action.indices, raw.length)) {\n return null;\n }\n\n return action.indices.map(index => ({\n start: children[index]!.start!,\n end: children[index]!.end!,\n content: '',\n }));\n }\n case 'duplicate': {\n if (!indicesAreValid(action.indices, raw.length)) {\n return null;\n }\n\n const content = [...action.indices]\n .sort((a, b) => a - b)\n .map(index => copySource(raw[index]!, usedIds))\n .join('');\n const at = parent.closingElement.start!;\n\n return [{ start: at, end: at, content }];\n }\n case 'append': {\n const content = copySource(raw[0] ?? '<div></div>', usedIds);\n const at = parent.closingElement.start!;\n\n return [{ start: at, end: at, content }];\n }\n default:\n return null;\n }\n } catch {\n return null;\n }\n};\n","import * as t from '@babel/types';\n\nimport { generateCode } from './helpers';\nimport type { NodeValueType } from './types';\n\n// Builds AST expressions and source text from JS values: the inverse of\n// reading them in `value.ts`.\n\nexport const createNodeFromValue = (\n type: NodeValueType,\n value: unknown,\n): t.Expression | null => {\n switch (type) {\n case 'boolean': {\n return t.booleanLiteral(value === true);\n }\n case 'number': {\n return t.numericLiteral(Number(value));\n }\n case 'string': {\n return t.stringLiteral(String(value));\n }\n case 'null': {\n return t.nullLiteral();\n }\n case 'array':\n case 'object':\n case 'unknown': {\n return null;\n }\n default: {\n return null;\n }\n }\n};\n\n// Builds an expression for a JS value: the inverse of `evaluateLiteral`\n// (#238). Each JS type maps to one kind of literal. Values with no literal\n// form (`undefined`, functions, symbols) give `null`. Inside an object the\n// property is left out; inside an array the item becomes `null`.\nexport const valueToExpression = (value: unknown): t.Expression | null => {\n if (typeof value === 'string') {\n return t.stringLiteral(value);\n }\n\n if (typeof value === 'number') {\n return value < 0\n ? t.unaryExpression('-', t.numericLiteral(-value))\n : t.numericLiteral(value);\n }\n\n if (typeof value === 'boolean') {\n return t.booleanLiteral(value);\n }\n\n if (value === null) {\n return t.nullLiteral();\n }\n\n if (Array.isArray(value)) {\n return t.arrayExpression(\n value.map(item => valueToExpression(item) ?? t.nullLiteral()),\n );\n }\n\n if (typeof value === 'object') {\n const properties: t.ObjectProperty[] = [];\n\n for (const [key, item] of Object.entries(value)) {\n const expr = valueToExpression(item);\n if (expr === null) {\n continue;\n }\n properties.push(t.objectProperty(t.stringLiteral(key), expr));\n }\n\n return t.objectExpression(properties);\n }\n\n return null;\n};\n\nexport const arrayExpressionToCode = (\n elements: t.ObjectExpression[],\n): string => {\n const nextAst = t.arrayExpression(elements);\n return generateCode(nextAst);\n};\n","import { parseExpression } from '@babel/parser';\nimport * as t from '@babel/types';\n\nimport { STRING_VALUED_TYPES } from './binding';\nimport { generateCode } from './helpers';\nimport type { SourceEdit } from './patch';\nimport type { BindingType } from './types';\nimport { isLosslesslyEvaluable, unwrapExpression } from './value';\nimport { valueToExpression } from './value-expression';\n\n// The source editors behind `update`: each turns one property edit on one\n// element into source spans, and never touches the tree.\n\n// What each editor below returns: the source spans to change, never a\n// changed tree, so everything else stays byte-identical (#239). An empty\n// array means \"handled, nothing to write\"; `null` means the edit failed.\nexport type EditResult = SourceEdit[] | null;\n\n// The span between `>` and `</`, i.e. everything the element encloses.\n// `null` for a self-closing element, which has nowhere to put children.\nexport const childrenRange = (\n element: t.JSXElement,\n): { start: number; end: number } | null => {\n const { openingElement, closingElement } = element;\n\n if (\n !closingElement ||\n openingElement.end == null ||\n closingElement.start == null\n ) {\n return null;\n }\n\n return { start: openingElement.end, end: closingElement.start };\n};\n\nexport const findAttribute = (\n opening: t.JSXOpeningElement,\n propertyName: string,\n): t.JSXAttribute | undefined => {\n return opening.attributes.find(\n (attr): attr is t.JSXAttribute =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === propertyName,\n );\n};\n\n// Where a new attribute goes: after the last attribute, or after the\n// element name when there are none.\nconst attributeInsertPoint = (opening: t.JSXOpeningElement): number | null => {\n const last = opening.attributes[opening.attributes.length - 1];\n\n return last?.end ?? opening.name.end ?? null;\n};\n\n// Replaces the element's text. With a single text child, only the trimmed\n// text is replaced, so the line breaks and indentation around it stay\n// (#239). Otherwise every text child is removed and `value` is written just\n// before the closing tag; nested elements stay.\n//\n// A self-closing element has nowhere to put text: this returns no edits,\n// and `update` reports success without changing anything.\nexport const editInnerText = (\n source: string,\n element: t.JSXElement,\n value: string,\n): EditResult => {\n const range = childrenRange(element);\n\n if (!range) {\n return [];\n }\n\n const [only] = element.children;\n\n if (\n element.children.length === 1 &&\n t.isJSXText(only) &&\n only.start != null &&\n only.end != null\n ) {\n // Measure the raw source, not `only.value`: Babel decodes entities and\n // CRLF in `value`, so its lengths don't match the source offsets.\n // `&nbsp;Old&nbsp;` would otherwise become `&New;`.\n const raw = source.slice(only.start, only.end);\n\n if (raw.trim() !== '') {\n const leading = raw.length - raw.trimStart().length;\n const trailing = raw.length - raw.trimEnd().length;\n\n return [\n {\n start: only.start + leading,\n end: only.end - trailing,\n content: value,\n },\n ];\n }\n }\n\n const edits: SourceEdit[] = [];\n\n for (const child of element.children) {\n if (t.isJSXText(child) && child.start != null && child.end != null) {\n edits.push({ start: child.start, end: child.end, content: '' });\n }\n }\n\n edits.push({ start: range.end, end: range.end, content: value });\n\n return edits;\n};\n\n// Replaces the element's children with the raw HTML, as written.\nexport const editInnerHTML = (\n element: t.JSXElement,\n value: string,\n): EditResult => {\n const range = childrenRange(element);\n\n if (!range) {\n return [];\n }\n\n return [{ start: range.start, end: range.end, content: value }];\n};\n\nexport const editRichtext = (\n element: t.JSXElement,\n value: string,\n): EditResult => {\n const edits: SourceEdit[] = [];\n const range = childrenRange(element);\n\n // richtext owns the element's content, so any prior markup goes.\n if (range && range.start !== range.end) {\n edits.push({ start: range.start, end: range.end, content: '' });\n }\n\n const opening = element.openingElement;\n const attribute = t.jsxAttribute(\n t.jsxIdentifier('dangerouslySetInnerHTML'),\n t.jsxExpressionContainer(\n t.objectExpression([\n t.objectProperty(t.identifier('__html'), t.stringLiteral(value)),\n ]),\n ),\n );\n const content = generateCode(attribute);\n const existing = findAttribute(opening, 'dangerouslySetInnerHTML');\n\n if (existing && existing.start != null && existing.end != null) {\n edits.push({\n start: existing.start,\n end: existing.end,\n content,\n indent: true,\n });\n\n return edits;\n }\n\n const insertAt = attributeInsertPoint(opening);\n\n if (insertAt == null) {\n return null;\n }\n\n edits.push({\n start: insertAt,\n end: insertAt,\n content: ` ${content}`,\n indent: true,\n });\n\n return edits;\n};\n\n// A `type: 'jsx'` value is arbitrary user-authored JSX, so it goes in as\n// written rather than being parsed into nodes and printed back out.\nexport const editJsxAttribute = (\n opening: t.JSXOpeningElement,\n propertyName: string,\n value: unknown,\n): EditResult => {\n const attribute = findAttribute(opening, propertyName);\n\n if (!attribute) {\n return null;\n }\n\n const content = `{${String(value).trim()}}`;\n\n if (attribute.value?.start != null && attribute.value.end != null) {\n return [\n {\n start: attribute.value.start,\n end: attribute.value.end,\n content,\n },\n ];\n }\n\n // Valueless shorthand (`<Icon icon />`): there is no value span to\n // overwrite, so append one after the attribute name.\n const insertAt = attribute.name.end;\n\n if (insertAt == null) {\n return null;\n }\n\n return [{ start: insertAt, end: insertAt, content: `=${content}` }];\n};\n\n// Whether the attribute holds an array or object literal, such as\n// `items={[...]}`. Other expressions (`className={cn(...)}`,\n// `items={rows}`) don't count: the panel doesn't edit their source, so a\n// string committed to them stays a string.\nconst holdsStructuralExpression = (value?: t.JSXAttribute['value']): boolean =>\n t.isJSXExpressionContainer(value) &&\n (t.isArrayExpression(unwrapExpression(value.expression)) ||\n t.isObjectExpression(unwrapExpression(value.expression)));\n\n// Parses committed text as an array or object literal, or `null`. Only\n// those shapes are accepted: `hello` also parses, as an identifier, and\n// writing `items={hello}` would turn a value into a variable reference.\nconst structuralSource = (value: string): t.Expression | null => {\n try {\n const expression = parseExpression(value.trim(), {\n plugins: ['jsx', 'typescript'],\n });\n\n return t.isArrayExpression(unwrapExpression(expression)) ||\n t.isObjectExpression(unwrapExpression(expression))\n ? expression\n : null;\n } catch {\n return null;\n }\n};\n\n// Builds the JSX attribute value for a value and its declared `type`\n// (#238). `current` is the value being replaced. Without a declared type,\n// as in most `items` bindings, `current` decides whether the value is\n// source code or a string, the same way `getStructuredValue` reads it.\nconst buildAttributeValue = (\n value: unknown,\n type?: BindingType,\n current?: t.JSXAttribute['value'],\n): t.JSXAttribute['value'] => {\n // Declared object or array: an expression. A string here is source text\n // from the Items or object editor, so parse it instead of quoting it.\n if (type === 'array' || type === 'object') {\n if (typeof value === 'string') {\n try {\n return t.jsxExpressionContainer(\n parseExpression(value.trim(), { plugins: ['jsx', 'typescript'] }),\n );\n } catch {\n return t.stringLiteral(value);\n }\n }\n\n const expr = valueToExpression(value);\n return expr ? t.jsxExpressionContainer(expr) : t.stringLiteral('');\n }\n\n // Otherwise each JS type maps to one kind of literal. A string stays a\n // string literal whatever it contains.\n if (typeof value === 'string') {\n // Except when the attribute holds an array or object literal: then the\n // string is its source text from the array editor. Quoting it would turn\n // `items={[...]}` into a string and break the document.\n if (\n holdsStructuralExpression(current) &&\n !(type && STRING_VALUED_TYPES.has(type))\n ) {\n const structural = structuralSource(value);\n\n if (structural) {\n return t.jsxExpressionContainer(structural);\n }\n }\n\n return t.stringLiteral(value);\n }\n\n const expr = valueToExpression(value);\n return expr ? t.jsxExpressionContainer(expr) : t.stringLiteral(String(value));\n};\n\nexport const editAttribute = (\n opening: t.JSXOpeningElement,\n propertyName: string,\n value: unknown,\n type?: BindingType,\n): EditResult => {\n const attribute = findAttribute(opening, propertyName);\n\n if (!attribute || attribute.start == null || attribute.end == null) {\n return null;\n }\n\n // Array or object source from the editors: check its shape, then replace\n // only the expression, so the unchanged items keep their formatting.\n if (\n typeof value === 'string' &&\n (type === 'array' ||\n type === 'object' ||\n (holdsStructuralExpression(attribute.value) &&\n !(type && STRING_VALUED_TYPES.has(type))))\n ) {\n const expression = structuralSource(value);\n\n if (expression && t.isJSXExpressionContainer(attribute.value)) {\n const text = value.trim();\n const lineComment = expression.trailingComments?.some(\n comment => comment.type === 'CommentLine',\n );\n\n return [\n {\n start: attribute.value.expression.start!,\n end: attribute.value.expression.end!,\n content: `${text}${lineComment ? '\\n' : ''}`,\n },\n ];\n }\n }\n\n // Print the whole attribute, so Babel decides the quoting and escaping.\n // The parsed name node is reused, so namespaced and dashed names stay as\n // written.\n const content = generateCode(\n t.jsxAttribute(\n attribute.name,\n buildAttributeValue(value, type, attribute.value),\n ),\n );\n\n return [\n { start: attribute.start, end: attribute.end, content, indent: true },\n ];\n};\n\n// Removes an attribute and the whitespace before it, leaving no gap. A\n// caller asks for this with `undefined`, since React treats an `undefined`\n// prop like a missing one (#426).\nexport const removeAttribute = (\n source: string,\n attribute: t.JSXAttribute,\n): EditResult => {\n if (attribute.start == null || attribute.end == null) {\n return null;\n }\n\n let start = attribute.start;\n\n while (start > 0 && /\\s/.test(source[start - 1]!)) {\n start -= 1;\n }\n\n return [{ start, end: attribute.end, content: '' }];\n};\n\n// Adds a missing attribute after the last one. Only for a real value:\n// clearing a field never creates the attribute (#426). When the last\n// attribute is on its own line, the new one goes on the next line with the\n// same indentation.\nexport const addAttribute = (\n source: string,\n opening: t.JSXOpeningElement,\n propertyName: string,\n value: unknown,\n type?: BindingType,\n): EditResult => {\n const insertAt = attributeInsertPoint(opening);\n\n if (insertAt == null) {\n return null;\n }\n\n // With `indent: true`, a newline is enough to line the new attribute up\n // under the last one.\n const lastStart = opening.attributes[opening.attributes.length - 1]?.start;\n const lineStart =\n lastStart == null ? -1 : source.lastIndexOf('\\n', lastStart - 1) + 1;\n const ownLine =\n lastStart != null &&\n lineStart > 0 &&\n /^\\s*$/.test(source.slice(lineStart, lastStart));\n const separator = ownLine ? '\\n' : ' ';\n\n const content =\n type === 'jsx'\n ? `${propertyName}={${String(value).trim()}}`\n : generateCode(\n t.jsxAttribute(\n t.jsxIdentifier(propertyName),\n buildAttributeValue(value, type),\n ),\n );\n\n return [\n {\n start: insertAt,\n end: insertAt,\n content: `${separator}${content}`,\n indent: true,\n },\n ];\n};\n\nexport const canEditAttributeValue = (\n attribute: t.JSXAttribute,\n value: unknown,\n type?: BindingType,\n) => {\n if (\n !t.isJSXExpressionContainer(attribute.value) ||\n t.isJSXEmptyExpression(attribute.value.expression) ||\n isLosslesslyEvaluable(attribute.value.expression)\n ) {\n return true;\n }\n\n // The array and object editors commit checked source text, which keeps\n // every expression, so accept it.\n return (\n typeof value === 'string' &&\n holdsStructuralExpression(attribute.value) &&\n !(type && STRING_VALUED_TYPES.has(type)) &&\n structuralSource(value) !== null\n );\n};\n","import { parse } from '@babel/parser';\nimport * as t from '@babel/types';\n\nimport {\n BINDING_PROP,\n DATA_ATTR,\n RESERVED_BINDING_PROPERTIES,\n} from '../../constants';\nimport { parseBinding, resolveBindings } from './binding';\nimport { editChildrenSource } from './children';\nimport { traverse } from './document';\nimport {\n type EditResult,\n addAttribute,\n canEditAttributeValue,\n childrenRange,\n editAttribute,\n editInnerHTML,\n editInnerText,\n editJsxAttribute,\n editRichtext,\n findAttribute,\n removeAttribute,\n} from './edit-source';\nimport { generateCode, unwrap, wrap } from './helpers';\nimport { getJSXTagName } from './jsx-name';\nimport { type SourceEdit, applyEdits } from './patch';\nimport type { BindingItem, BindingOptions } from './types';\n\n// Why an edit failed, with what a caller needs to name the cause (#270).\n// The cause is usually a wrong `property` or `label` in the element's\n// `data-binding`, not the value just typed.\nexport type UpdateFailure =\n | { reason: 'element-not-found'; dataId: string }\n | { reason: 'no-binding'; dataId: string }\n // The binding targets an attribute the editor owns (`data-id`,\n // `data-name`, `data-binding`), which a panel edit must not rewrite.\n | { reason: 'reserved-property'; dataId: string; property: string }\n // Asked to remove (`undefined`) a property whose binding is `required`.\n | { reason: 'required-property'; dataId: string; property: string }\n | {\n reason: 'binding-not-declared';\n dataId: string;\n label: string;\n property?: string;\n }\n | {\n reason: 'duplicate-binding';\n dataId: string;\n label: string;\n property?: string;\n count: number;\n }\n | { reason: 'attribute-not-found'; dataId: string; property: string }\n // `innerText` or `innerHTML` written to a self-closing element, which has\n // nowhere between its tags to put them (#552).\n | { reason: 'self-closing'; dataId: string; property: string }\n | { reason: 'unsupported-syntax'; dataId: string; property: string }\n | { reason: 'parse-error'; error: unknown };\n\nexport interface UpdateResult {\n code: string;\n success: boolean;\n // Set when `success` is false. The deprecated `bulkUpdate` reports\n // per-entry failures in `failures` instead.\n failure?: UpdateFailure;\n failures?: UpdateFailure[];\n}\n\n// What one `update` call asks for.\ninterface UpdateRequest {\n dataId: string;\n label: string;\n value: unknown;\n property?: string;\n options: BindingOptions;\n}\n\n// One element's outcome: the spans to write (possibly none, which still\n// counts as handled), or why it was refused.\ntype ElementEdit = { edits: SourceEdit[] } | { failure: UpdateFailure };\n\nconst hasDataId = (opening: t.JSXOpeningElement, dataId: string) =>\n opening.attributes.some(\n attr =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === DATA_ATTR.ID &&\n attr.value &&\n t.isStringLiteral(attr.value) &&\n attr.value.value === dataId,\n );\n\nconst findJSXAttribute = (opening: t.JSXOpeningElement, name: string) =>\n opening.attributes.find(\n (attr): attr is t.JSXAttribute =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === name,\n );\n\n// Step 1: the element's binding for the request, from the same sources\n// `extract` reads (#509, #513). Found by `property` when given, otherwise by\n// `label`. More than one match is an authoring mistake, reported rather than\n// resolved by picking one (#240).\nconst findBinding = (\n opening: t.JSXOpeningElement,\n { dataId, label, property, options }: UpdateRequest,\n): { binding: BindingItem } | { failure: UpdateFailure } => {\n const bindingAttr = findJSXAttribute(opening, DATA_ATTR.BINDING);\n\n // An attribute with no value declares nothing to check against.\n if (bindingAttr && !bindingAttr.value) {\n return { failure: { reason: 'no-binding', dataId } };\n }\n\n let own: BindingItem[] | undefined;\n\n if (bindingAttr?.value) {\n let bindingValue = '';\n\n if (t.isStringLiteral(bindingAttr.value)) {\n bindingValue = bindingAttr.value.value;\n } else if (t.isJSXExpressionContainer(bindingAttr.value)) {\n try {\n bindingValue = generateCode(bindingAttr.value.expression);\n } catch (error) {\n return { failure: { reason: 'parse-error', error } };\n }\n }\n\n own = parseBinding(bindingValue);\n }\n\n const keyAttr = findJSXAttribute(opening, DATA_ATTR.BINDING_KEY);\n const bindings = resolveBindings(\n own,\n keyAttr &&\n (keyAttr.value && t.isStringLiteral(keyAttr.value)\n ? keyAttr.value.value\n : null),\n getJSXTagName(opening),\n options,\n );\n\n if (!own && bindings.length === 0) {\n return { failure: { reason: 'no-binding', dataId } };\n }\n\n const matches = bindings.filter(binding =>\n property !== undefined\n ? binding.property === property\n : binding.label === label,\n );\n\n if (matches.length === 0) {\n return {\n failure: { reason: 'binding-not-declared', dataId, label, property },\n };\n }\n\n if (matches.length > 1) {\n return {\n failure: {\n reason: 'duplicate-binding',\n dataId,\n label,\n property,\n count: matches.length,\n },\n };\n }\n\n return { binding: matches[0]! };\n};\n\n// Step 2: what no edit may do, whatever the property: rewrite an attribute\n// the editor owns, or remove a `required` one (#426).\nconst checkEdit = (\n binding: BindingItem,\n { dataId, value }: UpdateRequest,\n): UpdateFailure | undefined => {\n const property = binding.property;\n\n if (RESERVED_BINDING_PROPERTIES.includes(property)) {\n return { reason: 'reserved-property', dataId, property };\n }\n\n if (value === undefined && binding.required) {\n return { reason: 'required-property', dataId, property };\n }\n\n return undefined;\n};\n\n// An editor's result as an `ElementEdit`: `null` becomes `onNull`'s failure.\nconst toElementEdit = (\n result: EditResult,\n onNull: () => UpdateFailure,\n): ElementEdit => (result ? { edits: result } : { failure: onNull() });\n\n// Step 3: the spans that set `binding`'s property on `element`. `undefined`\n// asks for the property to go: an attribute is removed, content is emptied.\nconst editProperty = (\n source: string,\n element: t.JSXElement,\n binding: BindingItem,\n { dataId, value, options }: UpdateRequest,\n): ElementEdit => {\n const opening = element.openingElement;\n const prop = binding.property;\n const unset = value === undefined;\n const couldNotUpdate = (): UpdateFailure => ({\n reason: 'parse-error',\n error: new Error(`could not update \"${prop}\"`),\n });\n\n // Text and HTML go between the tags, so a self-closing element can't take\n // them. Clearing them is fine: there's nothing to clear (#552).\n const contentWithoutSlot =\n !unset && String(value) !== '' && !childrenRange(element);\n\n switch (prop) {\n case BINDING_PROP.INNER_TEXT: {\n if (contentWithoutSlot) {\n return { failure: { reason: 'self-closing', dataId, property: prop } };\n }\n\n return toElementEdit(\n editInnerText(source, element, unset ? '' : String(value)),\n couldNotUpdate,\n );\n }\n\n case BINDING_PROP.INNER_HTML: {\n // `richtext` is written to an attribute, so it doesn't need one.\n if (contentWithoutSlot && binding.type !== 'richtext') {\n return { failure: { reason: 'self-closing', dataId, property: prop } };\n }\n\n return toElementEdit(\n binding.type === 'richtext'\n ? editRichtext(element, unset ? '' : String(value))\n : editInnerHTML(element, unset ? '' : String(value)),\n couldNotUpdate,\n );\n }\n\n case BINDING_PROP.CHILDREN: {\n // Children are edited one at a time (move, add, remove), so they can't\n // be removed as a whole.\n if (unset) {\n return {\n failure: { reason: 'unsupported-syntax', dataId, property: prop },\n };\n }\n\n return toElementEdit(\n editChildrenSource(source, element, value, options),\n () => ({\n reason: 'parse-error',\n error: new Error(\n 'Unsupported or stale children edit; source was preserved',\n ),\n }),\n );\n }\n\n default: {\n const attribute = findAttribute(opening, prop);\n\n if (unset) {\n // Already absent: nothing to remove, and nothing went wrong.\n return toElementEdit(\n attribute ? removeAttribute(source, attribute) : [],\n () => ({\n reason: 'parse-error',\n error: new Error(`could not remove \"${prop}\"`),\n }),\n );\n }\n\n // A declared property the element doesn't have yet is added when it's\n // given a real value, so a field that was switched off can be switched\n // on again. An empty string leaves it absent (#426).\n if (!attribute) {\n return toElementEdit(\n value === ''\n ? []\n : addAttribute(source, opening, prop, value, binding.type),\n () => ({ reason: 'attribute-not-found', dataId, property: prop }),\n );\n }\n\n if (\n binding.type !== 'jsx' &&\n !canEditAttributeValue(attribute, value, binding.type)\n ) {\n return {\n failure: { reason: 'unsupported-syntax', dataId, property: prop },\n };\n }\n\n return toElementEdit(\n binding.type === 'jsx'\n ? editJsxAttribute(opening, prop, value)\n : editAttribute(opening, prop, value, binding.type),\n () => ({ reason: 'attribute-not-found', dataId, property: prop }),\n );\n }\n }\n};\n\n// The three steps for one element.\nconst editElement = (\n source: string,\n element: t.JSXElement,\n request: UpdateRequest,\n): ElementEdit => {\n const found = findBinding(element.openingElement, request);\n\n if ('failure' in found) {\n return found;\n }\n\n const refused = checkEdit(found.binding, request);\n\n if (refused) {\n return { failure: refused };\n }\n\n return editProperty(source, element, found.binding, request);\n};\n\n// Sets one bound property of the element with `dataId` to `value`, and\n// returns the new source or why it couldn't.\n//\n// The binding is found by `property` when given, otherwise by `label`.\n// Pass `property` when you have it: a label is display text and can repeat\n// (#240). `options` are the binding sources the bindings were read with\n// (#509, #513).\nexport const update = (\n code: string,\n dataId: string,\n label: string,\n value: unknown,\n property?: string,\n options: BindingOptions = {},\n): UpdateResult => {\n const request: UpdateRequest = { dataId, label, value, property, options };\n\n try {\n const wrapped = wrap(code);\n const ast = parse(wrapped, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\n let changed = false;\n let failure: UpdateFailure | undefined;\n const edits: SourceEdit[] = [];\n\n // Every element carrying `dataId` is edited, so a duplicated id edits\n // each copy; the last refusal is the one reported.\n traverse(ast, {\n JSXElement(path) {\n if (!hasDataId(path.node.openingElement, dataId)) {\n return;\n }\n\n const result = editElement(wrapped, path.node, request);\n\n if ('failure' in result) {\n failure = result.failure;\n\n return;\n }\n\n edits.push(...result.edits);\n changed = true;\n },\n });\n\n if (!changed) {\n return {\n code,\n success: false,\n // No specific reason recorded means the traversal never reached the\n // target element at all.\n failure: failure ?? { reason: 'element-not-found', dataId },\n };\n }\n\n // Patch the original source: everything outside the recorded spans is\n // copied unchanged (#239).\n return { code: unwrap(applyEdits(wrapped, edits)), success: true };\n } catch (error) {\n console.error('❌ Code update error:', error);\n return { code, success: false, failure: { reason: 'parse-error', error } };\n }\n};\n\nexport interface UpdateEntry {\n dataId: string;\n label: string;\n value: unknown;\n property?: string;\n}\n\n// The result of `updateAll`: every entry applied, or none. On failure `code`\n// is the source as it came in, `index` says which entry was refused, and\n// `failure` says why.\nexport type UpdateAllResult =\n | { success: true; code: string }\n | { success: false; code: string; failure: UpdateFailure; index: number };\n\n// Applies several edits as one: all of them, in array order, or none. The\n// first entry that fails stops the run and the source comes back untouched,\n// so a caller can commit the result as a single change (#425). An entry sees\n// the source the earlier ones left, and a later entry for the same\n// `dataId`/`property` wins.\n//\n// Each entry re-parses the source the one before it produced, so every offset\n// is fresh, and the outcome matches applying the entries one at a time (#239).\nexport const updateAll = (\n raw: string,\n entries: UpdateEntry[],\n options: BindingOptions = {},\n): UpdateAllResult => {\n let current = raw;\n\n for (const [index, entry] of entries.entries()) {\n const result = update(\n current,\n entry.dataId,\n entry.label,\n entry.value,\n entry.property,\n options,\n );\n\n if (!result.success) {\n return {\n success: false,\n code: raw,\n failure: result.failure ?? {\n reason: 'element-not-found',\n dataId: entry.dataId,\n },\n index,\n };\n }\n\n current = result.code;\n }\n\n return { success: true, code: current };\n};\n\n/**\n * @deprecated Not atomic: when an entry fails, the ones before and after it\n * are still applied, and the returned `code` carries them. Use `updateAll`,\n * which applies every entry or none. Will be removed in the next major.\n */\nexport const bulkUpdate = (\n raw: string,\n entries: UpdateEntry[],\n): UpdateResult => {\n let current = raw;\n const failures: UpdateFailure[] = [];\n\n for (const entry of entries) {\n const result = update(\n current,\n entry.dataId,\n entry.label,\n entry.value,\n entry.property,\n );\n current = result.code;\n if (!result.success && result.failure) {\n failures.push(result.failure);\n }\n }\n\n return failures.length > 0\n ? { code: current, success: false, failures }\n : { code: current, success: true };\n};\n","import * as t from '@babel/types';\n\nimport { type SourceEdit, applyEdits } from './patch';\nimport { parseArrayExpression } from './value';\n\n// Gaps between dense elements contain only whitespace, comments and one\n// comma. Scan those gaps, never the expressions (which can contain JSX,\n// regexes, templates and nested commas).\nconst commaIn = (source: string, start: number, end: number): number | null => {\n let comma: number | null = null;\n\n for (let at = start; at < end; at++) {\n if (/\\s/.test(source[at]!)) {\n continue;\n }\n\n if (source.startsWith('/*', at)) {\n const close = source.indexOf('*/', at + 2);\n\n if (close < 0 || close + 2 > end) {\n return null;\n }\n\n at = close + 1;\n } else if (source.startsWith('//', at)) {\n const newline = source.indexOf('\\n', at + 2);\n at = newline < 0 ? end : newline;\n } else if (source[at] === ',' && comma === null) {\n comma = at;\n } else {\n return null;\n }\n }\n\n return comma;\n};\n\nexport const denseArraySource = (source: string) => {\n const array = parseArrayExpression(source);\n\n // Holes/spreads have source positions but no stable visible item count.\n // Value edits can preserve them; structural edits deliberately refuse.\n if (\n !array ||\n array.elements.some(\n node => !t.isExpression(node) || node.extra?.parenthesized,\n )\n ) {\n return null;\n }\n\n const elements = array.elements as t.Expression[];\n const commas = elements\n .slice(0, -1)\n .map((node, index) =>\n commaIn(source, node.end!, elements[index + 1]!.start!),\n );\n\n if (commas.some(comma => comma === null)) {\n return null;\n }\n\n const last = elements.at(-1);\n const trailing = last ? commaIn(source, last.end!, array.end! - 1) : null;\n\n return { array, elements, commas: commas as number[], trailing };\n};\n\n// Keep presentation and mutation on the same syntax boundary. Consumers can\n// use this before offering structural controls, while every write still calls\n// denseArraySource() again so stale source is refused at commit time.\nexport const canStructurallyEditArray = (source: string) =>\n denseArraySource(source) !== null;\n\nexport const validArrayIndices = (indices: Iterable<number>, length: number) =>\n [...indices].every(\n index => Number.isInteger(index) && index >= 0 && index < length,\n );\n\nexport const reorderArraySource = (\n source: string,\n elements: t.Expression[],\n next: t.Expression[],\n): string =>\n applyEdits(\n source,\n elements.map((node, index) => ({\n start: node.start!,\n end: node.end!,\n content: source.slice(next[index]!.start!, next[index]!.end!),\n })),\n );\n\nexport const removeArraySource = (\n source: string,\n data: NonNullable<ReturnType<typeof denseArraySource>>,\n indices: Set<number>,\n): string => {\n const edits: SourceEdit[] = [];\n const removedCommas = new Set<number>();\n const { elements, commas, trailing } = data;\n\n // Each consecutive removed run consumes its following commas. A run\n // ending at the last element consumes the preceding separator instead;\n // a trailing comma, when present, stays a trailing comma.\n for (let index = 0; index < elements.length; index++) {\n if (!indices.has(index)) {\n continue;\n }\n\n const start = index;\n\n while (index + 1 < elements.length && indices.has(index + 1)) {\n index++;\n }\n\n for (let current = start; current <= index; current++) {\n const node = elements[current]!;\n edits.push({ start: node.start!, end: node.end!, content: '' });\n\n if (current < elements.length - 1) {\n removedCommas.add(commas[current]!);\n }\n }\n\n if (index === elements.length - 1) {\n if (trailing !== null) {\n removedCommas.add(trailing);\n } else if (start > 0) {\n removedCommas.add(commas[start - 1]!);\n }\n }\n }\n\n for (const comma of removedCommas) {\n edits.push({ start: comma, end: comma + 1, content: '' });\n }\n\n return applyEdits(source, edits);\n};\n\nexport const appendArraySource = (\n source: string,\n data: NonNullable<ReturnType<typeof denseArraySource>>,\n copies: string[],\n): string => {\n const last = data.elements.at(-1);\n\n if (!last || copies.length === 0) {\n return source;\n }\n\n // Insert before the old trailing gap so line comments cannot swallow a\n // new item, and keep an existing trailing comma in its original role.\n return applyEdits(source, [\n {\n start: last.end!,\n end: last.end!,\n content: `, ${copies.join(', ')}`,\n },\n ]);\n};\n","import { parseExpression } from '@babel/parser';\nimport * as t from '@babel/types';\nimport { nanoid } from 'nanoid';\n\nimport { BINDING_PROP } from '../../constants';\nimport { moveSelectedIndices, removeIndices } from '../selection';\nimport {\n appendArraySource,\n denseArraySource,\n removeArraySource,\n reorderArraySource,\n validArrayIndices,\n} from './array-source';\nimport { generateCode } from './helpers';\nimport { type SourceEdit, applyEdits } from './patch';\nimport type {\n BindingRenderLeaf,\n BindingRenderMap,\n NodeValueType,\n} from './types';\nimport {\n extractNodeValue,\n extractObjectProperties,\n isLosslesslyEvaluable,\n parseArrayExpression,\n parseValue,\n} from './value';\nimport { createNodeFromValue, valueToExpression } from './value-expression';\n\n// Array edits are source patches. Parsing locates the requested value or\n// element; unrelated expressions, comments and formatting are not printed\n// again. Structural edits require dense arrays; value edits preserve holes\n// and spreads at their existing source positions. `null` means refusal.\n\nexport type ItemKind = 'object' | 'primitive';\n\nexport interface ArrayItem {\n // Position in the array's elements, which is what every function here\n // indexes by. Items of one kind are not renumbered, so a mixed array\n // stays addressable.\n index: number;\n kind: ItemKind;\n node: t.Expression;\n}\n\nconst elementsOf = (code: string) =>\n parseArrayExpression(code)?.elements ?? null;\n\nconst kindOf = (element: t.Expression): ItemKind =>\n t.isObjectExpression(element) ? 'object' : 'primitive';\n\n// Omit holes and spreads from the visible list without renumbering source\n// positions. A spread is not one runtime value that the panel can edit.\nexport const parseItems = (code: string): ArrayItem[] | null => {\n const elements = elementsOf(code);\n\n return (\n elements?.flatMap((node, index) =>\n t.isExpression(node) ? [{ index, kind: kindOf(node), node }] : [],\n ) ?? null\n );\n};\n\nconst resolveRenderLeaf = (\n render: BindingRenderMap | undefined,\n key: string,\n): BindingRenderLeaf | null => {\n const leaf = render?.[key];\n\n return leaf && 'type' in leaf ? (leaf as BindingRenderLeaf) : null;\n};\n\n// Escapes text for a template literal's raw source: backticks, `${`,\n// backslashes and carriage returns. Without this, pasted markup can throw\n// in `@babel/types`, and CRLF doesn't survive a round trip.\nconst toTemplateRaw = (value: string): string => {\n return value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/`/g, '\\\\`')\n .replace(/\\$\\{/g, '\\\\${')\n .replace(/\\r/g, '\\\\r');\n};\n\n// Builds the node a property should hold, from the value the panel produced.\n// Returns `undefined` when the value can't be represented, which callers\n// treat as \"leave the source alone\".\nconst buildPropertyValue = (\n value: unknown,\n declaredType: NodeValueType,\n renderLeaf: BindingRenderLeaf | null,\n current: t.Expression,\n): t.Expression | undefined => {\n // innerHTML is raw markup: a template literal keeps it as written.\n if (renderLeaf?.property === BINDING_PROP.INNER_HTML) {\n const raw = String(value);\n\n return t.templateLiteral(\n [t.templateElement({ raw: toTemplateRaw(raw), cooked: raw }, true)],\n [],\n );\n }\n\n // JSX when the render map declares `jsx`, or when the current value is\n // already JSX without a declaration, so it stays JSX (#298).\n if (\n renderLeaf?.type === 'jsx' ||\n t.isJSXElement(current) ||\n t.isJSXFragment(current)\n ) {\n const trimmed = String(value).trim();\n\n // Anything that isn't markup is a plain string for this property.\n if (!trimmed.startsWith('<')) {\n return t.stringLiteral(trimmed);\n }\n\n try {\n return parseExpression(trimmed, { plugins: ['jsx', 'typescript'] });\n } catch {\n return undefined;\n }\n }\n\n if (declaredType === 'array' || declaredType === 'object') {\n // The nested Items editor commits source text; parse it as is. The\n // object editor and the fallback text area commit a JS value instead.\n if (typeof value === 'string') {\n try {\n return parseExpression(value, { plugins: ['jsx', 'typescript'] });\n } catch {\n return undefined;\n }\n }\n\n // A JS value can be rebuilt exactly only when the property held nothing\n // but literals. Otherwise the edit is refused and the source stays.\n if (!isLosslesslyEvaluable(current)) {\n return undefined;\n }\n\n return valueToExpression(value) ?? undefined;\n }\n\n // Scalars arrive as typed text, so convert first: the string `'true'`\n // would otherwise become `false` for a boolean.\n return createNodeFromValue(declaredType, parseValue(value)) ?? undefined;\n};\n\nexport const updateArrayItemProperty = (\n code: string,\n index: number,\n key: string,\n value: unknown,\n render?: BindingRenderMap,\n): string | null => {\n const elements = elementsOf(code);\n const element = elements?.[index];\n\n if (!elements || !t.isObjectExpression(element)) {\n return null;\n }\n\n const target = element.properties.find(\n (property): property is t.ObjectProperty =>\n t.isObjectProperty(property) &&\n t.isIdentifier(property.key) &&\n property.key.name === key,\n );\n\n if (!target) {\n return null;\n }\n\n const declaredType = extractObjectProperties(element)[key]?.type ?? 'string';\n const nextValue = buildPropertyValue(\n value,\n declaredType,\n resolveRenderLeaf(render, key),\n target.value as t.Expression,\n );\n\n if (!nextValue) {\n return null;\n }\n\n let serialized =\n typeof value === 'string' &&\n (declaredType === 'array' ||\n declaredType === 'object' ||\n t.isJSXElement(nextValue) ||\n t.isJSXFragment(nextValue))\n ? value.trim()\n : generateCode(nextValue);\n\n if (\n nextValue.trailingComments?.some(comment => comment.type === 'CommentLine')\n ) {\n serialized += '\\n';\n }\n\n // A shorthand property shares the key/value span: expand it explicitly.\n const content = target.shorthand ? `${key}: ${serialized}` : serialized;\n\n return applyEdits(code, [\n { start: target.value.start!, end: target.value.end!, content },\n ]);\n};\n\nexport const updateArrayItemValue = (\n code: string,\n index: number,\n value: unknown,\n): string | null => {\n const elements = elementsOf(code);\n const element = elements?.[index];\n\n if (!elements || !t.isExpression(element)) {\n return null;\n }\n\n const nextValue = createNodeFromValue(\n extractNodeValue(element).type,\n parseValue(value),\n );\n\n if (!nextValue) {\n return null;\n }\n\n return applyEdits(code, [\n {\n start: element.start!,\n end: element.end!,\n content: generateCode(nextValue),\n },\n ]);\n};\n\nexport const moveArrayItem = (\n code: string,\n from: number,\n to: number,\n): string | null => {\n const data = denseArraySource(code);\n\n if (\n !data ||\n !validArrayIndices([from], data.elements.length) ||\n !Number.isInteger(to)\n ) {\n return null;\n }\n\n // Preserve the existing splice destination semantics (including append).\n const next = [...data.elements];\n const [moved] = next.splice(from, 1);\n next.splice(to, 0, moved!);\n\n return reorderArraySource(code, data.elements, next);\n};\n\nexport const moveArrayItems = (\n code: string,\n indices: Set<number>,\n direction: 'up' | 'down',\n): { code: string; indices: Set<number> } | null => {\n const data = denseArraySource(code);\n\n if (\n !data ||\n !validArrayIndices(indices, data.elements.length) ||\n !['up', 'down'].includes(direction)\n ) {\n return null;\n }\n\n const next = moveSelectedIndices(data.elements, indices, direction);\n\n return {\n code: reorderArraySource(code, data.elements, next.items),\n indices: next.indices,\n };\n};\n\n// Keep the last-item guard until the empty-array creation contract (#316)\n// is implemented. It must count the visible kind in a mixed array.\nexport const removeArrayItems = (\n code: string,\n indices: Set<number>,\n kind?: ItemKind,\n): string | null => {\n const data = denseArraySource(code);\n\n if (!data || !validArrayIndices(indices, data.elements.length)) {\n return null;\n }\n\n const remaining = removeIndices(data.elements, indices);\n const survivors =\n kind === undefined\n ? remaining\n : remaining.filter(node => kindOf(node) === kind);\n\n if (!survivors.length) {\n return null;\n }\n\n return removeArraySource(code, data, indices);\n};\n\n// Copy exact source; only static object keys / JSX identities get changed.\n// Re-evaluating modeled property values here would erase expressions.\nconst copyItem = (\n code: string,\n element: t.Expression,\n generateId: () => string,\n usedIds: Set<string>,\n): string | null => {\n const edits: SourceEdit[] = [];\n let unsupported = false;\n const reserveId = (id: string) => {\n if (usedIds.has(id)) {\n unsupported = true;\n }\n\n usedIds.add(id);\n\n return JSON.stringify(id);\n };\n\n t.traverseFast(element, node => {\n if (!t.isJSXOpeningElement(node)) {\n return;\n }\n\n const ids = node.attributes.filter(\n (attr): attr is t.JSXAttribute =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name, { name: 'data-id' }),\n );\n const attr = ids[0];\n\n if (\n ids.length > 1 ||\n (attr &&\n (!t.isStringLiteral(attr.value) ||\n node.attributes\n .slice(node.attributes.indexOf(attr) + 1)\n .some(a => t.isJSXSpreadAttribute(a))))\n ) {\n unsupported = true;\n return;\n }\n\n if (attr && t.isStringLiteral(attr.value)) {\n edits.push({\n start: attr.value.start!,\n end: attr.value.end!,\n content: reserveId(generateId()),\n });\n }\n });\n\n if (t.isObjectExpression(element)) {\n const keys = element.properties.filter(\n (prop): prop is t.ObjectProperty =>\n t.isObjectProperty(prop) &&\n !prop.computed &&\n (t.isIdentifier(prop.key, { name: 'key' }) ||\n t.isStringLiteral(prop.key, { value: 'key' })),\n );\n const key = keys[0];\n\n if (\n keys.length > 1 ||\n (key &&\n (!t.isStringLiteral(key.value) ||\n element.properties\n .slice(element.properties.indexOf(key) + 1)\n .some(\n prop =>\n t.isSpreadElement(prop) ||\n ('computed' in prop && prop.computed),\n )))\n ) {\n return null;\n }\n\n if (key && t.isStringLiteral(key.value)) {\n edits.push({\n start: key.value.start!,\n end: key.value.end!,\n content: reserveId(`${key.value.value}-${generateId()}`),\n });\n }\n }\n\n if (unsupported) {\n return null;\n }\n\n return applyEdits(\n code.slice(element.start!, element.end!),\n edits.map(edit => ({\n ...edit,\n start: edit.start - element.start!,\n end: edit.end - element.start!,\n })),\n );\n};\n\nexport const duplicateArrayItems = (\n code: string,\n indices: Set<number>,\n generateId: () => string = () => nanoid(6),\n): string | null => {\n const data = denseArraySource(code);\n\n if (\n !data ||\n !indices.size ||\n !validArrayIndices(indices, data.elements.length)\n ) {\n return null;\n }\n\n const usedIds = new Set<string>();\n\n t.traverseFast(data.array, node => {\n if (\n t.isJSXAttribute(node) &&\n t.isJSXIdentifier(node.name, { name: 'data-id' }) &&\n t.isStringLiteral(node.value)\n ) {\n usedIds.add(node.value.value);\n } else if (\n t.isObjectProperty(node) &&\n !node.computed &&\n (t.isIdentifier(node.key, { name: 'key' }) ||\n t.isStringLiteral(node.key, { value: 'key' })) &&\n t.isStringLiteral(node.value)\n ) {\n usedIds.add(node.value.value);\n }\n });\n\n const copies = [...indices]\n .sort((a, b) => a - b)\n .map(index => copyItem(code, data.elements[index]!, generateId, usedIds));\n\n return copies.every((copy): copy is string => copy !== null)\n ? appendArraySource(code, data, copies)\n : null;\n};\n\n// Appends a copy of the first item of `kind`. Items are never created from\n// scratch, because their shape comes from their siblings. So an array\n// needs at least one item to be editable, and `removeArrayItems` never\n// empties it. `null` means there is no item of `kind` to copy; the first\n// one has to be written in the source (#316).\nexport const appendArrayItem = (\n code: string,\n kind: ItemKind,\n generateId: () => string = () => nanoid(6),\n): string | null => {\n const data = denseArraySource(code);\n const index = data?.elements.findIndex(node => kindOf(node) === kind) ?? -1;\n\n return index < 0\n ? null\n : duplicateArrayItems(code, new Set([index]), generateId);\n};\n"],"mappings":";;;;;;;;AAgCA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;ACjCA,MAAM,UAAU,QAAwB;CACtC,MAAM,QAAQ,IACX,QAAQ,OAAO,EAAE,CAAC,CAClB,QAAQ,UAAU,EAAE,CAAC,CACrB,MAAM,IAAI;CAEb,MAAM,SAAS,MAAM,QAAQ,KAAK,SAAS;EACzC,IAAI,CAAC,KAAK,KAAK,GACb,OAAO;EAET,MAAM,QAAQ,KAAK,MAAM,QAAQ;EACjC,OAAO,KAAK,IAAI,KAAK,QAAQ,EAAE,EAAE,UAAU,CAAC;CAC9C,GAAG,QAAQ;CAEX,OAAO,WAAW,WACd,IAAI,KAAK,IACT,MAAM,KAAI,SAAQ,KAAK,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI;AACrD;AAKA,MAAa,oBAAoB,SAAyB;CACxD,IAAI,UAAU;CAEd,OACEA,aAAE,iBAAiB,OAAO,KAC1BA,aAAE,wBAAwB,OAAO,KACjCA,aAAE,sBAAsB,OAAO,KAC/BA,aAAE,kBAAkB,OAAO,KAC3BA,aAAE,0BAA0B,OAAO,GAEnC,UAAU,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