@kubuild/core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,9 +52,30 @@ export interface ClonedSubtreeResult {
52
52
  clonedNode: Node;
53
53
  idMap: Map<string, string>;
54
54
  }
55
+ /**
56
+ * Keys (in step payloads, legacy `props.action.payload`, and node props) whose string value
57
+ * is a reference to another node's id. When a subtree is cloned with fresh ids, references
58
+ * that point at a node *inside* that subtree are rewritten to the clone's new id; references
59
+ * to nodes outside the subtree are left untouched.
60
+ */
61
+ export declare const NODE_ID_REFERENCE_KEYS: ReadonlySet<string>;
62
+ /**
63
+ * Rewrites node-id references inside a single (already cloned) node so they follow `idMap`.
64
+ * Covers action pipeline step payloads (incl. onSuccess/onError branches), `formConfig.formId`,
65
+ * id-reference props (e.g. `modalId`, `formId`), `#anchor` hrefs, and the legacy `props.action`
66
+ * payload. Mutates the node in place; callers must pass a clone they own.
67
+ */
68
+ export declare function remapNodeReferences(node: Node, idMap: ReadonlyMap<string, string>): void;
69
+ /**
70
+ * Deep-clones a node subtree assigning every node a fresh id via `idGen`, preserving every
71
+ * other `Node` field (props, styles, animation, actions, formConfig, and any future field),
72
+ * then rewrites intra-subtree node-id references (see {@link remapNodeReferences}).
73
+ */
74
+ export declare function cloneNodeTreeWithFreshIds(root: Node, idGen: (oldId: string, node: Node) => string): ClonedSubtreeResult;
55
75
  /**
56
76
  * Recursively clone a node and its entire subtree, generating fresh unique IDs
57
- * for every node while preserving types, props, and responsive styles.
77
+ * for every node while preserving every other node field (props, styles, animation,
78
+ * actions, formConfig) and remapping intra-subtree node-id references.
58
79
  */
59
80
  export declare function cloneTreeWithNewIds(root: Node, idGenerator?: (oldId: string) => string, existingIds?: Set<string>): ClonedSubtreeResult;
60
81
  //# sourceMappingURL=command-tree-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-tree-utils.d.ts","sourceRoot":"","sources":["../../src/document/command-tree-utils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efinition, AnimationConfig, ActionPipeline, FormConfig } from '@kubuild/schema';
2
- export type DocumentChangeType = 'NODE_INSERTED' | 'NODE_MOVED' | 'PROPS_UPDATED' | 'STYLE_UPDATED' | 'ANIMATION_UPDATED' | 'ACTIONS_UPDATED' | 'FORM_CONFIG_UPDATED' | 'NODE_REMOVED' | 'NODE_DUPLICATED' | 'NODE_WRAPPED' | 'NODE_UNGROUPED' | 'NODE_REPLACED';
1
+ import { PageDocument, Node, ResponsiveStyles, StyleDefinition, AnimationConfig, ActionPipeline, FormConfig, Theme } from '@kubuild/schema';
2
+ export type DocumentChangeType = 'NODE_INSERTED' | 'NODE_MOVED' | 'PROPS_UPDATED' | 'STYLE_UPDATED' | 'ANIMATION_UPDATED' | 'ACTIONS_UPDATED' | 'FORM_CONFIG_UPDATED' | 'NODE_REMOVED' | 'NODE_DUPLICATED' | 'NODE_WRAPPED' | 'NODE_UNGROUPED' | 'NODE_REPLACED' | 'THEME_UPDATED';
3
3
  export interface DocumentChangeEvent {
4
4
  type: DocumentChangeType;
5
5
  timestamp: string;
@@ -184,4 +184,21 @@ export declare function ungroupNodeFrame(document: PageDocument, params: Ungroup
184
184
  * Returns a new PageDocument and a NODE_REPLACED event.
185
185
  */
186
186
  export declare function replaceNode(document: PageDocument, params: ReplaceNodeParams): CommandResult;
187
+ export interface UpdateThemeParams {
188
+ /**
189
+ * Token changes. With `merge` (default) each group is merged token-by-token and a token
190
+ * set to `null` is removed; without `merge` the theme is replaced. `null` removes the
191
+ * whole theme.
192
+ */
193
+ theme: {
194
+ [G in keyof Theme]?: Record<string, string | number | null> | null;
195
+ } | null;
196
+ merge?: boolean;
197
+ }
198
+ /**
199
+ * Update the document-level design tokens (`PageDocument.theme`, STORA-551).
200
+ * The result is validated with `ThemeSchema`, so unsafe keys/values (CSS injection) throw.
201
+ * Returns a new PageDocument and a THEME_UPDATED event keyed to the root node.
202
+ */
203
+ export declare function updateTheme(document: PageDocument, params: UpdateThemeParams): CommandResult;
187
204
  //# sourceMappingURL=commands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/document/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,eAAe,EAGf,eAAe,EAEf,cAAc,EAEd,UAAU,EAEX,MAAM,iBAAiB,CAAC;AASzB,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,YAAY,GACZ,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,iBAAiB,GACjB,qBAAqB,GACrB,cAAc,GACd,iBAAiB,GACjB,cAAc,GACd,gBAAgB,GAChB,eAAe,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,mBAAmB,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B;;;OAGG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Manager,
31
31
  HistoryEngine: () => HistoryEngine,
32
32
  MigrationRegistry: () => MigrationRegistry,
33
+ NODE_ID_REFERENCE_KEYS: () => NODE_ID_REFERENCE_KEYS,
33
34
  RuntimeStateStore: () => RuntimeStateStore,
34
35
  addArtboard: () => addArtboard,
35
36
  applyFieldTransform: () => applyFieldTransform,
@@ -37,7 +38,9 @@ __export(index_exports, {
37
38
  buildSampleVariablesFromCatalog: () => buildSampleVariablesFromCatalog,
38
39
  calculateChecksum: () => calculateChecksum,
39
40
  canMigrate: () => canMigrate,
41
+ canonicalizeTextPropsInPlace: () => canonicalizeTextPropsInPlace,
40
42
  checkZipBomb: () => checkZipBomb,
43
+ cloneNodeTreeWithFreshIds: () => cloneNodeTreeWithFreshIds,
41
44
  cloneTemplateAsPage: () => cloneTemplateAsPage,
42
45
  cloneTreeWithNewIds: () => cloneTreeWithNewIds,
43
46
  collectArtboardReferenceNodes: () => collectArtboardReferenceNodes,
@@ -114,6 +117,7 @@ __export(index_exports, {
114
117
  previewImportPackage: () => previewImportPackage,
115
118
  remapAssetReferences: () => remapAssetReferences,
116
119
  remapDocumentAssetReferences: () => remapDocumentAssetReferences,
120
+ remapNodeReferences: () => remapNodeReferences,
117
121
  removeArtboard: () => removeArtboard,
118
122
  removeNode: () => removeNode,
119
123
  renameArtboard: () => renameArtboard,
@@ -141,6 +145,7 @@ __export(index_exports, {
141
145
  updateFormConfig: () => updateFormConfig,
142
146
  updateProps: () => updateProps,
143
147
  updateStyle: () => updateStyle,
148
+ updateTheme: () => updateTheme,
144
149
  validateDocument: () => validateDocument,
145
150
  validateDocumentSecurity: () => validateDocumentSecurity,
146
151
  validateFieldValue: () => validateFieldValue,
@@ -472,26 +477,84 @@ function defaultIdGenerator(oldId, existingIds) {
472
477
  }
473
478
  return candidate;
474
479
  }
475
- function cloneTreeWithNewIds(root, idGenerator, existingIds) {
480
+ var NODE_ID_REFERENCE_KEYS = /* @__PURE__ */ new Set([
481
+ "modalId",
482
+ "modalNodeId",
483
+ "targetModalId",
484
+ "targetNodeId",
485
+ "nodeId",
486
+ "formId",
487
+ "targetId"
488
+ ]);
489
+ var ANCHOR_REFERENCE_KEYS = /* @__PURE__ */ new Set(["url", "href"]);
490
+ function remapReferenceValue(key, value, idMap) {
491
+ if (typeof value !== "string") return value;
492
+ if (NODE_ID_REFERENCE_KEYS.has(key)) {
493
+ return idMap.get(value) ?? idMap.get(value.trim()) ?? value;
494
+ }
495
+ if (ANCHOR_REFERENCE_KEYS.has(key) && value.startsWith("#")) {
496
+ const mapped = idMap.get(value.slice(1));
497
+ return mapped ? `#${mapped}` : value;
498
+ }
499
+ return value;
500
+ }
501
+ function remapReferenceRecord(record, idMap) {
502
+ for (const [key, value] of Object.entries(record)) {
503
+ record[key] = remapReferenceValue(key, value, idMap);
504
+ }
505
+ }
506
+ function remapStepReferences(steps, idMap) {
507
+ if (!Array.isArray(steps)) return;
508
+ for (const step of steps) {
509
+ if (step.payload && typeof step.payload === "object") {
510
+ remapReferenceRecord(step.payload, idMap);
511
+ }
512
+ remapStepReferences(step.onSuccess, idMap);
513
+ remapStepReferences(step.onError, idMap);
514
+ }
515
+ }
516
+ function remapNodeReferences(node, idMap) {
517
+ if (node.props && typeof node.props === "object") {
518
+ remapReferenceRecord(node.props, idMap);
519
+ const legacyAction = node.props.action;
520
+ if (legacyAction && typeof legacyAction === "object" && legacyAction.payload && typeof legacyAction.payload === "object" && !Array.isArray(legacyAction.payload)) {
521
+ remapReferenceRecord(legacyAction.payload, idMap);
522
+ }
523
+ }
524
+ if (node.formConfig && typeof node.formConfig.formId === "string") {
525
+ node.formConfig.formId = idMap.get(node.formConfig.formId) ?? node.formConfig.formId;
526
+ }
527
+ if (Array.isArray(node.actions)) {
528
+ for (const pipeline of node.actions) {
529
+ remapStepReferences(pipeline.steps, idMap);
530
+ }
531
+ }
532
+ }
533
+ function cloneNodeTreeWithFreshIds(root, idGen) {
476
534
  const idMap = /* @__PURE__ */ new Map();
477
- const idGen = idGenerator || ((oldId) => defaultIdGenerator(oldId, existingIds));
535
+ const clonedNodes = [];
478
536
  function cloneRecursive(node) {
479
- const newId = idGen(node.id);
537
+ const newId = idGen(node.id, node);
480
538
  idMap.set(node.id, newId);
481
- const clonedProps = node.props ? deepClone(node.props) : void 0;
482
- const clonedStyles = node.styles ? deepClone(node.styles) : void 0;
483
- const clonedChildren = node.children ? node.children.map((child) => cloneRecursive(child)) : [];
484
- return {
539
+ const { children, ...rest } = node;
540
+ const cloned = {
541
+ ...deepClone(rest),
485
542
  id: newId,
486
- type: node.type,
487
- ...clonedProps ? { props: clonedProps } : {},
488
- ...clonedStyles ? { styles: clonedStyles } : {},
489
- children: clonedChildren
543
+ children: children ? children.map((child) => cloneRecursive(child)) : []
490
544
  };
545
+ clonedNodes.push(cloned);
546
+ return cloned;
491
547
  }
492
548
  const clonedNode = cloneRecursive(root);
549
+ for (const cloned of clonedNodes) {
550
+ remapNodeReferences(cloned, idMap);
551
+ }
493
552
  return { clonedNode, idMap };
494
553
  }
554
+ function cloneTreeWithNewIds(root, idGenerator, existingIds) {
555
+ const idGen = idGenerator || ((oldId) => defaultIdGenerator(oldId, existingIds));
556
+ return cloneNodeTreeWithFreshIds(root, (oldId) => idGen(oldId));
557
+ }
495
558
 
496
559
  // src/document/commands.ts
497
560
  var import_schema3 = require("@kubuild/schema");
@@ -1033,6 +1096,53 @@ function replaceNode(document, params) {
1033
1096
  }
1034
1097
  };
1035
1098
  }
1099
+ function updateTheme(document, params) {
1100
+ const { theme, merge = true } = params;
1101
+ const newDoc = deepClone(document);
1102
+ const previousTheme = newDoc.theme ? deepClone(newDoc.theme) : void 0;
1103
+ if (theme === null) {
1104
+ delete newDoc.theme;
1105
+ } else {
1106
+ const next = {};
1107
+ for (const group of import_schema3.THEME_TOKEN_GROUPS) {
1108
+ const base = merge ? { ...previousTheme?.[group] ?? {} } : {};
1109
+ const patch = theme[group];
1110
+ if (patch === null) {
1111
+ continue;
1112
+ }
1113
+ if (patch) {
1114
+ for (const [key, value] of Object.entries(patch)) {
1115
+ if (value === null) {
1116
+ delete base[key];
1117
+ } else {
1118
+ base[key] = value;
1119
+ }
1120
+ }
1121
+ }
1122
+ if (Object.keys(base).length > 0) {
1123
+ next[group] = base;
1124
+ }
1125
+ }
1126
+ const parsed = import_schema3.ThemeSchema.parse(next);
1127
+ if (Object.keys(parsed).length > 0) {
1128
+ newDoc.theme = parsed;
1129
+ } else {
1130
+ delete newDoc.theme;
1131
+ }
1132
+ }
1133
+ return {
1134
+ document: newDoc,
1135
+ event: {
1136
+ type: "THEME_UPDATED",
1137
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1138
+ nodeId: newDoc.document.id,
1139
+ payload: {
1140
+ theme: newDoc.theme,
1141
+ previousTheme
1142
+ }
1143
+ }
1144
+ };
1145
+ }
1036
1146
 
1037
1147
  // src/document/artboards.ts
1038
1148
  var import_schema4 = require("@kubuild/schema");
@@ -4396,6 +4506,56 @@ defaultMigrationRegistry.register({
4396
4506
  return migrated;
4397
4507
  }
4398
4508
  });
4509
+ function canonicalizeTextPropsInPlace(root, basePath = "document") {
4510
+ const changed = [];
4511
+ const walk2 = (value, path) => {
4512
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
4513
+ const node = value;
4514
+ const props = node.props;
4515
+ const rule = typeof node.type === "string" ? (0, import_schema9.getCanonicalTextPropRule)(node.type) : void 0;
4516
+ if (rule && props && typeof props === "object" && !Array.isArray(props)) {
4517
+ const record = props;
4518
+ const presentAliases = rule.aliases.filter((alias) => record[alias] !== void 0);
4519
+ if (presentAliases.length > 0) {
4520
+ const displayedKey = rule.legacyReadOrder.find((key) => record[key] !== void 0);
4521
+ if (node.type === "text" && displayedKey === "content" && record.as === void 0 && record.tag === void 0) {
4522
+ record.as = "p";
4523
+ }
4524
+ if (displayedKey !== void 0 && displayedKey !== rule.canonical) {
4525
+ record[rule.canonical] = record[displayedKey];
4526
+ }
4527
+ for (const alias of presentAliases) {
4528
+ delete record[alias];
4529
+ changed.push(`${path}.props.${alias}`);
4530
+ }
4531
+ }
4532
+ }
4533
+ if (Array.isArray(node.children)) {
4534
+ node.children.forEach((child, index) => walk2(child, `${path}.children.${index}`));
4535
+ }
4536
+ };
4537
+ walk2(root, basePath);
4538
+ return changed;
4539
+ }
4540
+ defaultMigrationRegistry.register({
4541
+ fromVersion: "1.1.0",
4542
+ toVersion: "1.2.0",
4543
+ description: "Rename deprecated text prop aliases to canonical names (heading/text/paragraph/link/badge/blockquote -> text, button -> label)",
4544
+ migrate: (rawDoc, context) => {
4545
+ const migrated = deepClone(rawDoc);
4546
+ migrated.version = "1.2.0";
4547
+ const changed = canonicalizeTextPropsInPlace(migrated.document);
4548
+ if (changed.length > 0) {
4549
+ context.warn({
4550
+ code: "PROP_ALIAS_MIGRATED",
4551
+ message: "Deprecated text prop aliases were renamed to their canonical names.",
4552
+ step: "1.1.0->1.2.0",
4553
+ paths: changed
4554
+ });
4555
+ }
4556
+ return migrated;
4557
+ }
4558
+ });
4399
4559
  function canMigrate(sourceVersion, targetVersion = import_schema9.CURRENT_SCHEMA_VERSION, registry = defaultMigrationRegistry) {
4400
4560
  if (!sourceVersion || !targetVersion) return false;
4401
4561
  if (sourceVersion === targetVersion) return true;
@@ -4500,6 +4660,16 @@ function migrateDocument(rawDocument, options = {}) {
4500
4660
  };
4501
4661
  }
4502
4662
  if (dryRun) {
4663
+ const simulatedWarnings = [];
4664
+ try {
4665
+ let simulated = deepClone(doc);
4666
+ for (let i = 0; i < path.length - 1; i++) {
4667
+ const step = registry.getStep(path[i], path[i + 1]);
4668
+ if (!step) break;
4669
+ simulated = step.migrate(simulated, { warn: (w) => simulatedWarnings.push(w) });
4670
+ }
4671
+ } catch {
4672
+ }
4503
4673
  return {
4504
4674
  success: true,
4505
4675
  diagnostic: {
@@ -4508,7 +4678,8 @@ function migrateDocument(rawDocument, options = {}) {
4508
4678
  targetVersion,
4509
4679
  migrationPath: path,
4510
4680
  stepsApplied: path.length - 1,
4511
- dryRun: true
4681
+ dryRun: true,
4682
+ ...simulatedWarnings.length > 0 ? { warnings: simulatedWarnings } : {}
4512
4683
  }
4513
4684
  };
4514
4685
  }
@@ -5324,6 +5495,18 @@ var importStoraPackage = importPackage;
5324
5495
 
5325
5496
  // src/io/load-project.ts
5326
5497
  var import_schema11 = require("@kubuild/schema");
5498
+ function migrateProjectArtboards(project) {
5499
+ let changed = false;
5500
+ const artboards = project.artboards.map((artboard) => {
5501
+ const version = artboard.document.version;
5502
+ if (version === import_schema11.CURRENT_SCHEMA_VERSION || !canMigrate(version)) return artboard;
5503
+ const migration = migrateDocument(artboard.document);
5504
+ if (!migration.success || !migration.document) return artboard;
5505
+ changed = true;
5506
+ return { ...artboard, document: migration.document };
5507
+ });
5508
+ return changed ? { ...project, artboards } : project;
5509
+ }
5327
5510
  var DEFAULT_PAGE_ARTBOARD_ID = "artboard-page-1";
5328
5511
  function wrapPageDocumentAsProject(document, options = {}) {
5329
5512
  const artboardId = options.artboardId ?? DEFAULT_PAGE_ARTBOARD_ID;
@@ -5373,7 +5556,7 @@ function loadProjectDocument(raw) {
5373
5556
  }
5374
5557
  return {
5375
5558
  success: true,
5376
- project: parsed.data,
5559
+ project: migrateProjectArtboards(parsed.data),
5377
5560
  wrappedFromLegacyPage: false,
5378
5561
  errors: []
5379
5562
  };
@@ -5843,18 +6026,7 @@ function compareManifestsSemantically(expected, actual, options = {}) {
5843
6026
 
5844
6027
  // src/io/template-utils.ts
5845
6028
  var import_schema12 = require("@kubuild/schema");
5846
- var CORE_BUILTIN_COMPONENTS = /* @__PURE__ */ new Set([
5847
- "page",
5848
- "section",
5849
- "container",
5850
- "columns",
5851
- "column",
5852
- "heading",
5853
- "text",
5854
- "image",
5855
- "button",
5856
- "collection"
5857
- ]);
6029
+ var CORE_BUILTIN_COMPONENTS = new Set(import_schema12.BUILTIN_COMPONENT_TYPES);
5858
6030
  function validateTemplate(value) {
5859
6031
  const parseResult = import_schema12.TemplateRecordSchema.safeParse(value);
5860
6032
  if (parseResult.success) {
@@ -5965,22 +6137,6 @@ function saveDraftAsTemplate(draft, metadata, options = {}) {
5965
6137
  custom: metadata.custom ? deepClone(metadata.custom) : void 0
5966
6138
  });
5967
6139
  }
5968
- function cloneTreeWithFreshIds(root, idGen) {
5969
- function cloneRec(node) {
5970
- const newId = idGen(node.id, node);
5971
- const clonedProps = node.props ? deepClone(node.props) : void 0;
5972
- const clonedStyles = node.styles ? deepClone(node.styles) : void 0;
5973
- const clonedChildren = node.children ? node.children.map((child) => cloneRec(child)) : [];
5974
- return {
5975
- id: newId,
5976
- type: node.type,
5977
- ...clonedProps ? { props: clonedProps } : {},
5978
- ...clonedStyles ? { styles: clonedStyles } : {},
5979
- children: clonedChildren
5980
- };
5981
- }
5982
- return cloneRec(root);
5983
- }
5984
6140
  function cloneTemplateAsPage(templateOrDoc, options = {}) {
5985
6141
  let sourceDoc;
5986
6142
  let templateOrigin = null;
@@ -6016,7 +6172,7 @@ function cloneTemplateAsPage(templateOrDoc, options = {}) {
6016
6172
  return candidate;
6017
6173
  };
6018
6174
  const idGen = options.idGenerator || defaultIdGen;
6019
- const clonedRootNode = cloneTreeWithFreshIds(sourceDoc.document, idGen);
6175
+ const { clonedNode: clonedRootNode } = cloneNodeTreeWithFreshIds(sourceDoc.document, idGen);
6020
6176
  const rootPageNode = {
6021
6177
  ...clonedRootNode,
6022
6178
  type: "page"
@@ -6424,6 +6580,7 @@ function isFormValid(errors) {
6424
6580
  DocumentHistoryManager,
6425
6581
  HistoryEngine,
6426
6582
  MigrationRegistry,
6583
+ NODE_ID_REFERENCE_KEYS,
6427
6584
  RuntimeStateStore,
6428
6585
  addArtboard,
6429
6586
  applyFieldTransform,
@@ -6431,7 +6588,9 @@ function isFormValid(errors) {
6431
6588
  buildSampleVariablesFromCatalog,
6432
6589
  calculateChecksum,
6433
6590
  canMigrate,
6591
+ canonicalizeTextPropsInPlace,
6434
6592
  checkZipBomb,
6593
+ cloneNodeTreeWithFreshIds,
6435
6594
  cloneTemplateAsPage,
6436
6595
  cloneTreeWithNewIds,
6437
6596
  collectArtboardReferenceNodes,
@@ -6508,6 +6667,7 @@ function isFormValid(errors) {
6508
6667
  previewImportPackage,
6509
6668
  remapAssetReferences,
6510
6669
  remapDocumentAssetReferences,
6670
+ remapNodeReferences,
6511
6671
  removeArtboard,
6512
6672
  removeNode,
6513
6673
  renameArtboard,
@@ -6535,6 +6695,7 @@ function isFormValid(errors) {
6535
6695
  updateFormConfig,
6536
6696
  updateProps,
6537
6697
  updateStyle,
6698
+ updateTheme,
6538
6699
  validateDocument,
6539
6700
  validateDocumentSecurity,
6540
6701
  validateFieldValue,