@elytracms/studio 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/components/assets/asset-selection.d.ts +1 -1
  2. package/dist/components/assets/asset-selection.js +2 -2
  3. package/dist/components/assets/asset-selection.js.map +1 -1
  4. package/dist/components/builder/clipboard-actions.js +1 -1
  5. package/dist/components/builder/clipboard-actions.js.map +1 -1
  6. package/dist/components/builder/composition-field-editor.js +7 -7
  7. package/dist/components/builder/composition-field-editor.js.map +1 -1
  8. package/dist/components/builder/inline-edit.js +4 -3
  9. package/dist/components/builder/inline-edit.js.map +1 -1
  10. package/dist/components/builder/insert-context.js +1 -1
  11. package/dist/components/builder/insert-context.js.map +1 -1
  12. package/dist/components/builder/layout-inspector.js +2 -2
  13. package/dist/components/builder/layout-inspector.js.map +1 -1
  14. package/dist/components/builder/node-factory.js +7 -7
  15. package/dist/components/builder/node-factory.js.map +1 -1
  16. package/dist/components/builder/page-tree.js +1 -1
  17. package/dist/components/builder/page-tree.js.map +1 -1
  18. package/dist/components/builder/property-inspector.js +2 -2
  19. package/dist/components/builder/property-inspector.js.map +1 -1
  20. package/dist/components/builder/reuse-context.js +2 -2
  21. package/dist/components/builder/reuse-context.js.map +1 -1
  22. package/dist/components/builder/reuse.js +5 -4
  23. package/dist/components/builder/reuse.js.map +1 -1
  24. package/dist/components/cms/cell.js +1 -1
  25. package/dist/components/cms/cell.js.map +1 -1
  26. package/dist/components/cms/cms-store.js +13 -1
  27. package/dist/components/cms/cms-store.js.map +1 -1
  28. package/dist/components/cms/detail-editor.js +23 -6
  29. package/dist/components/cms/detail-editor.js.map +1 -1
  30. package/dist/components/cms/editable-cell.js +4 -4
  31. package/dist/components/cms/editable-cell.js.map +1 -1
  32. package/dist/components/cms/field-control.js +9 -9
  33. package/dist/components/cms/field-control.js.map +1 -1
  34. package/dist/components/cms/relation-picker.d.ts +2 -2
  35. package/dist/components/cms/relation-picker.js +5 -5
  36. package/dist/components/cms/relation-picker.js.map +1 -1
  37. package/dist/components/components/component-detail.js +1 -1
  38. package/dist/components/components/component-detail.js.map +1 -1
  39. package/dist/components/components/components-index.js +1 -1
  40. package/dist/components/components/components-index.js.map +1 -1
  41. package/dist/components/components/registry-browser.js +2 -2
  42. package/dist/components/components/registry-browser.js.map +1 -1
  43. package/dist/components/extensions/extensions-view.js +1 -1
  44. package/dist/components/extensions/extensions-view.js.map +1 -1
  45. package/dist/components/redirects/redirects-schema.js +10 -5
  46. package/dist/components/redirects/redirects-schema.js.map +1 -1
  47. package/dist/components/users/users-schema.js +7 -4
  48. package/dist/components/users/users-schema.js.map +1 -1
  49. package/dist/lib/clipboard/paste-target.js +1 -1
  50. package/dist/lib/clipboard/paste-target.js.map +1 -1
  51. package/dist/lib/dnd/drop-rules.js +2 -2
  52. package/dist/lib/dnd/drop-rules.js.map +1 -1
  53. package/dist/lib/dnd/gap-drag.js +2 -2
  54. package/dist/lib/dnd/gap-drag.js.map +1 -1
  55. package/dist/lib/i18n/i18n.d.ts +10 -1
  56. package/dist/lib/i18n/i18n.js +48 -3
  57. package/dist/lib/i18n/i18n.js.map +1 -1
  58. package/dist/lib/i18n/index.d.ts +1 -1
  59. package/dist/lib/i18n/index.js +1 -1
  60. package/dist/lib/i18n/index.js.map +1 -1
  61. package/dist/lib/i18n/messages.en.js +14 -0
  62. package/dist/lib/i18n/messages.en.js.map +1 -1
  63. package/dist/lib/i18n/types.d.ts +13 -0
  64. package/dist/lib/i18n/types.js.map +1 -1
  65. package/dist/lib/persona/labels.d.ts +2 -2
  66. package/dist/lib/persona/labels.js +3 -3
  67. package/dist/lib/persona/labels.js.map +1 -1
  68. package/dist/lib/references/reference-model.js +1 -1
  69. package/dist/lib/references/reference-model.js.map +1 -1
  70. package/dist/lib/registry/preview.js +15 -15
  71. package/dist/lib/registry/preview.js.map +1 -1
  72. package/dist/lib/registry/project-components.js +6 -13
  73. package/dist/lib/registry/project-components.js.map +1 -1
  74. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"users-schema.js","sourceRoot":"","sources":["../../../src/components/users/users-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD;;;;;;;;;;;;GAYG;AACH,kFAAkF;AAClF,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,EAAE,CAAA;AAE9C,MAAM,CAAC,MAAM,kBAAkB,GAAkB,mBAAmB,CAAC,KAAK,CAAC;IACzE,EAAE,EAAE,MAAM;IACV,4EAA4E;IAC5E,qFAAqF;IACrF,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE;IAC/C,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;QACzF,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;QAC3F;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,GAAG,iBAAiB,CAAC;YAC/B,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;SACxB;KACF;CACF,CAAC,CAAA","sourcesContent":["import { collectionDefSchema } from '@elytracms/core/cms-core'\nimport type { CollectionDef } from '@elytracms/core/cms-core'\nimport { roleOptions } from '@elytracms/core/persistence'\n\n/**\n * The built-in **users** field lens (EC-240, AD-19). Users are a separate rail —\n * NOT a `cmsDocuments` collection (`collectionKindSchema` is `document|asset`) —\n * so this `CollectionDef` exists only to drive the portable list/edit surfaces\n * over the users {@link CollectionViewSource}. The rail's *user-ness* comes from\n * the source's capabilities (admin-only, no publish/versions/create), never the\n * schema `kind`.\n *\n * Identity fields (`name`, `email`) are **auth-owned** and read-only here — an\n * admin manages a member's *role* (and, later, project-declared custom fields\n * over the `meta` bag, mirroring assets); the person edits their own name/email\n * via account settings. A v1 default; a project may extend the field set later.\n */\n// Derived from the ONE role policy (EC-240c) — no hardcoded duplicate of the role\n// set. Reflects the shipped default today; a project's custom policy flows through.\nexport const USER_ROLE_OPTIONS = roleOptions()\n\nexport const usersCollectionDef: CollectionDef = collectionDefSchema.parse({\n id: 'user',\n // Users aren't a CMS `kind`; 'document' just satisfies the lens schema. The\n // source's capabilities (adminOnly, no publish/versions/create) carry the semantics.\n kind: 'document',\n titleField: 'name',\n form: { label: 'Users', labelSingular: 'user' },\n fields: [\n { name: 'name', type: 'text', form: { label: 'Name', readOnly: true }, filterable: true },\n { name: 'email', type: 'text', form: { label: 'Email', readOnly: true }, filterable: true },\n {\n name: 'role',\n type: 'select',\n options: [...USER_ROLE_OPTIONS],\n filterable: true,\n form: { label: 'Role' },\n },\n ],\n})\n"]}
1
+ {"version":3,"file":"users-schema.js","sourceRoot":"","sources":["../../../src/components/users/users-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD;;;;;;;;;;;;GAYG;AACH,kFAAkF;AAClF,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,EAAE,CAAA;AAE9C,MAAM,CAAC,MAAM,kBAAkB,GAAkB,mBAAmB,CAAC,KAAK,CAAC;IACzE,EAAE,EAAE,MAAM;IACV,4EAA4E;IAC5E,qFAAqF;IACrF,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,MAAM;IAClB,kFAAkF;IAClF,6EAA6E;IAC7E,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,aAAa,EAAE,QAAQ,CAAC,0BAA0B,CAAC,EAAE;IAClG,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,wBAAwB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;QACrH,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;QACvH;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,GAAG,iBAAiB,CAAC;YAC/B,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,wBAAwB,CAAC,EAAE;SACpD;KACF;CACF,CAAC,CAAA","sourcesContent":["import { collectionDefSchema } from '@elytracms/core/cms-core'\nimport type { CollectionDef } from '@elytracms/core/cms-core'\nimport { roleOptions } from '@elytracms/core/persistence'\nimport { msgLabel } from '@elytracms/studio/lib/i18n'\n\n/**\n * The built-in **users** field lens (EC-240, AD-19). Users are a separate rail —\n * NOT a `cmsDocuments` collection (`collectionKindSchema` is `document|asset`) —\n * so this `CollectionDef` exists only to drive the portable list/edit surfaces\n * over the users {@link CollectionViewSource}. The rail's *user-ness* comes from\n * the source's capabilities (admin-only, no publish/versions/create), never the\n * schema `kind`.\n *\n * Identity fields (`name`, `email`) are **auth-owned** and read-only here — an\n * admin manages a member's *role* (and, later, project-declared custom fields\n * over the `meta` bag, mirroring assets); the person edits their own name/email\n * via account settings. A v1 default; a project may extend the field set later.\n */\n// Derived from the ONE role policy (EC-240c) — no hardcoded duplicate of the role\n// set. Reflects the shipped default today; a project's custom policy flows through.\nexport const USER_ROLE_OPTIONS = roleOptions()\n\nexport const usersCollectionDef: CollectionDef = collectionDefSchema.parse({\n id: 'user',\n // Users aren't a CMS `kind`; 'document' just satisfies the lens schema. The\n // source's capabilities (adminOnly, no publish/versions/create) carry the semantics.\n kind: 'document',\n titleField: 'name',\n // EC-241: built-in rail labels resolve through the message catalog (msgLabel) — a\n // consumer's translation catalog localizes them without a per-rail override.\n form: { label: msgLabel('users.rail.label'), labelSingular: msgLabel('users.rail.labelSingular') },\n fields: [\n { name: 'name', type: 'text', form: { label: msgLabel('users.field.name.label'), readOnly: true }, filterable: true },\n { name: 'email', type: 'text', form: { label: msgLabel('users.field.email.label'), readOnly: true }, filterable: true },\n {\n name: 'role',\n type: 'select',\n options: [...USER_ROLE_OPTIONS],\n filterable: true,\n form: { label: msgLabel('users.field.role.label') },\n },\n ],\n})\n"]}
@@ -1,6 +1,6 @@
1
1
  import { getNode, getParentInfo } from '@elytracms/core/project-graph';
2
2
  function shortId(componentId) {
3
- return componentId.replace('base.primitives.', '').replace('project.', '');
3
+ return componentId.replace('base.', '').replace('project.', '');
4
4
  }
5
5
  export function resolvePasteTarget(args) {
6
6
  const { root, getManifest } = args;
@@ -1 +1 @@
1
- {"version":3,"file":"paste-target.js","sourceRoot":"","sources":["../../../src/lib/clipboard/paste-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAkBtE,SAAS,OAAO,CAAC,WAAmB;IAClC,OAAO,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AAC5E,CAAC;AAED,MAAM,UAAU,kBAA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A;IACH,CAAC;IAED,8EAA8E;IAC9E,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAA;AACtF,CAAC","sourcesContent":["import { getNode, getParentInfo } from '@elytracms/core/project-graph'\nimport type { ComponentNode, InsertTarget } from '@elytracms/core/project-graph'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\n\n/**\n * Paste landing-spot resolution (EC-175) — the same placement rule the Insert\n * dialog uses (`insert-context.ts`): a pasted subtree lands *into*\n * the anchor node's child slot when it has one, else *after* the anchor as a\n * sibling, else appended to the page root. Pure and selection-driven so the\n * canvas, the page tree, and keyboard paste all share one rule.\n */\n\nexport interface PasteTarget {\n target: InsertTarget\n /** Human label of where the paste lands (notices/debugging). */\n destinationLabel: string\n}\n\nfunction shortId(componentId: string): string {\n return componentId.replace('base.primitives.', '').replace('project.', '')\n}\n\nexport function resolvePasteTarget(args: {\n root: ComponentNode\n /** The anchor node (usually the selection); `null` falls back to the root. */\n anchorId: string | null\n getManifest: (componentId: string) => ComponentManifest | undefined\n}): PasteTarget {\n const { root, getManifest } = args\n const anchor = args.anchorId !== null ? getNode(root, args.anchorId) : undefined\n const node = anchor ?? root\n\n const manifest = getManifest(node.componentId)\n const childSlot =\n manifest?.slots.find((s) => s.name === 'children') ??\n manifest?.slots.find((s) => s.name !== 'outlet')\n if (childSlot) {\n return {\n target: { parentId: node.id, slot: childSlot.name },\n destinationLabel: `${shortId(node.componentId)} · ${childSlot.name}`,\n }\n }\n\n const info = getParentInfo(root, node.id)\n if (info) {\n return {\n target: { parentId: info.parent.id, slot: info.slot, index: info.index + 1 },\n destinationLabel: `${shortId(info.parent.componentId)} · ${info.slot}`,\n }\n }\n\n // Leaf root with no declared slots (degenerate graphs): append to `children`.\n return { target: { parentId: root.id, slot: 'children' }, destinationLabel: 'root' }\n}\n"]}
1
+ {"version":3,"file":"paste-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AI,EAAE,CAAC;QACT,OAAO;YACL,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE;YAC5E,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE;SACvE,CAAA;IACH,CAAC;IAED,8EAA8E;IAC9E,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAA;AACtF,CAAC","sourcesContent":["import { getNode, getParentInfo } from '@elytracms/core/project-graph'\nimport type { ComponentNode, InsertTarget } from '@elytracms/core/project-graph'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\n\n/**\n * Paste landing-spot resolution (EC-175) — the same placement rule the Insert\n * dialog uses (`insert-context.ts`): a pasted subtree lands *into*\n * the anchor node's child slot when it has one, else *after* the anchor as a\n * sibling, else appended to the page root. Pure and selection-driven so the\n * canvas, the page tree, and keyboard paste all share one rule.\n */\n\nexport interface PasteTarget {\n target: InsertTarget\n /** Human label of where the paste lands (notices/debugging). */\n destinationLabel: string\n}\n\nfunction shortId(componentId: string): string {\n return componentId.replace('base.', '').replace('project.', '')\n}\n\nexport function resolvePasteTarget(args: {\n root: ComponentNode\n /** The anchor node (usually the selection); `null` falls back to the root. */\n anchorId: string | null\n getManifest: (componentId: string) => ComponentManifest | undefined\n}): PasteTarget {\n const { root, getManifest } = args\n const anchor = args.anchorId !== null ? getNode(root, args.anchorId) : undefined\n const node = anchor ?? root\n\n const manifest = getManifest(node.componentId)\n const childSlot =\n manifest?.slots.find((s) => s.name === 'children') ??\n manifest?.slots.find((s) => s.name !== 'outlet')\n if (childSlot) {\n return {\n target: { parentId: node.id, slot: childSlot.name },\n destinationLabel: `${shortId(node.componentId)} · ${childSlot.name}`,\n }\n }\n\n const info = getParentInfo(root, node.id)\n if (info) {\n return {\n target: { parentId: info.parent.id, slot: info.slot, index: info.index + 1 },\n destinationLabel: `${shortId(info.parent.componentId)} · ${info.slot}`,\n }\n }\n\n // Leaf root with no declared slots (degenerate graphs): append to `children`.\n return { target: { parentId: root.id, slot: 'children' }, destinationLabel: 'root' }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { DEFAULT_SLOT, GRID_COMPONENT_ID, OUTLET_SLOT, STACK_COMPONENT_ID, getNode, getParentInfo, gridContainerNode, isDescendantOf, removeNode, updateNode, } from '@elytracms/core/project-graph';
1
+ import { DEFAULT_SLOT, GRID_COMPONENT_ID, OUTLET_SLOT, STACK_COMPONENT_ID, getNode, getParentInfo, gridContainerNode, isDescendantOf, isStaticProp, removeNode, updateNode, } from '@elytracms/core/project-graph';
2
2
  function rejected(code, reason) {
3
3
  return { eligible: false, code, reason };
4
4
  }
@@ -182,7 +182,7 @@ export function applyWrap(args) {
182
182
  }
183
183
  function staticPropValue(node, name) {
184
184
  const prop = node.props?.[name];
185
- return prop?.kind === 'static' ? prop.value : undefined;
185
+ return isStaticProp(prop) ? prop.value : undefined;
186
186
  }
187
187
  /**
188
188
  * The flow axis of a container — the axis its children stack along, and
@@ -1 +1 @@
1
- {"version":3,"file":"drop-rules.js","sourceRoot":"","sources":["../../../src/lib/dnd/drop-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,UAAU,GACX,MAAM,+BAA+B,CAAA;AAmGtC,SAAS,QAAQ,CAAC,IAAuB,EAAE,MAAc;IACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAC1C,CAAC;AAED,8EAA8E;AAC9E,aAAa;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AAQ,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1F,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAMtC;IACC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,MAAM,CAAA;IACzB,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,KAAK,GAAG,IAAI;YAAE,OAAO,QAAQ,CAAA;QACjC,IAAI,KAAK,GAAG,IAAI;YAAE,OAAO,OAAO,CAAA;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAA;AACzC,CAAC;AAaD,MAAM,UAAU,gBAAgB,CAC9B,UAA0B,EAC1B,QAAsB;IAEtB,IAAI,UAAU,CAAC,QAAQ;QAAE,OAAO,QAAQ,CAAA;IACxC,OAAO,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACvD,CAAC","sourcesContent":["import {\n DEFAULT_SLOT,\n GRID_COMPONENT_ID,\n OUTLET_SLOT,\n STACK_COMPONENT_ID,\n getNode,\n getParentInfo,\n gridContainerNode,\n isDescendantOf,\n removeNode,\n updateNode,\n} from '@elytracms/core/project-graph'\nimport type { ComponentNode, GridContainerOptions, InsertTarget } from '@elytracms/core/project-graph'\n\n/**\n * Drag & drop eligibility rules (EC-160 + EC-162, vision §3.1) — pure\n * graph-level functions with **no DOM or UI dependencies**. The canvas and the\n * page tree both resolve drops through `resolveDrop`, so the two surfaces can\n * never disagree about what a manifest slot allow-list permits, which children\n * a component accepts, or whether a move would create a cycle.\n *\n * The drop-zone model is position-based: `into` a slot, `before`/`after` a\n * sibling along the parent's flow axis, and the EC-162 gesture positions\n * `left`/`right` — dropping *beside* an element wraps both in a two-column\n * `Grid` container (see `applyWrap`).\n */\n\n// ---------------------------------------------------------------------------\n// Inputs\n// ---------------------------------------------------------------------------\n\n/**\n * The manifest slice the rules evaluate. Structural (not the full\n * `ComponentManifest`) so tests and future callers can feed minimal lookups.\n */\nexport interface SlotRule {\n name: string\n /** Restrict which component ids may be inserted (omit to allow any). */\n allow?: string[]\n}\n\nexport interface ManifestRules {\n slots: SlotRule[]\n}\n\n/** Resolve a component id to its manifest slot rules (undefined = unknown component). */\nexport type ManifestLookup = (componentId: string) => ManifestRules | undefined\n\n/** What is being dragged. */\nexport type DragSubject =\n /** An existing node of the current page — a completed drop is a `move`. */\n | { kind: 'node'; nodeId: string; componentId: string }\n /** A new subtree (blocks-panel tile) — a completed drop is an `insert`. */\n | { kind: 'component'; componentId: string }\n\n/**\n * Where, relative to a reference node, the drop would land. `into`, `before`\n * and `after` are the EC-160 positions; `left`/`right` are the EC-162 gesture\n * positions — \"beside\" the reference, wrapping both elements in a two-column\n * `Grid` container.\n */\nexport type DropPosition = 'into' | 'before' | 'after' | 'left' | 'right'\n\n/** The side of the reference an EC-162 wrap gesture drops on. */\nexport type WrapSide = 'left' | 'right'\n\nexport interface DropLocation {\n /** The reference node id (the hovered node/row). */\n nodeId: string\n position: DropPosition\n}\n\n// ---------------------------------------------------------------------------\n// Outcomes\n// ---------------------------------------------------------------------------\n\nexport type DropRejectionCode =\n /** The reference node does not exist in the tree. */\n | 'missing-target'\n /** `into` on a component that declares no insertable slot. */\n | 'no-slot'\n /** The target slot's manifest allow-list rejects the dragged component. */\n | 'not-allowed'\n /** Moving a node into itself or its own subtree (cycle). */\n | 'own-subtree'\n /** The page root cannot be moved, and nothing can drop beside it. */\n | 'root'\n /** Structurally valid but changes nothing (dropping a node onto its own position). */\n | 'no-op'\n\nexport interface DropRejection {\n eligible: false\n code: DropRejectionCode\n reason: string\n}\n\n/** An eligible drop: exactly one builder action (move, insert, or wrap) commits it. */\nexport type DropPlan =\n | { eligible: true; kind: 'move'; nodeId: string; target: InsertTarget }\n | { eligible: true; kind: 'insert'; target: InsertTarget }\n /**\n * EC-162 wrap gesture: the reference node and the dragged subject become the\n * two columns of a new `Grid` container, created atomically (`applyWrap`).\n * `nodeId` is present when the subject is an existing node (a move-wrap);\n * absent for blocks-panel components (an insert-wrap via `buildNode`).\n */\n | { eligible: true; kind: 'wrap'; referenceId: string; side: WrapSide; nodeId?: string }\n\nexport type DropResolution = DropPlan | DropRejection\n\nfunction rejected(code: DropRejectionCode, reason: string): DropRejection {\n return { eligible: false, code, reason }\n}\n\n// ---------------------------------------------------------------------------\n// Slot rules\n// ---------------------------------------------------------------------------\n\n/**\n * The slot an `into` drop inserts into: the default `children` slot when\n * declared, else the first authored slot that is not the layout `outlet`.\n * Mirrors the shell's insert-context resolution so click-insert and\n * drag-insert land in the same place.\n */\nexport function primaryInsertSlot(manifest: ManifestRules | undefined): SlotRule | undefined {\n if (!manifest) return undefined\n return (\n manifest.slots.find((s) => s.name === DEFAULT_SLOT) ??\n manifest.slots.find((s) => s.name !== OUTLET_SLOT)\n )\n}\n\n/** True when a component can receive `into` drops at all (declares an insertable slot). */\nexport function canNestInto(getManifest: ManifestLookup, componentId: string): boolean {\n return primaryInsertSlot(getManifest(componentId)) !== undefined\n}\n\n/** True when a slot's allow-list (if any) permits the component id. */\nexport function slotAllows(slot: SlotRule | undefined, componentId: string): boolean {\n if (!slot?.allow) return true\n return slot.allow.includes(componentId)\n}\n\n// ---------------------------------------------------------------------------\n// Resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve a prospective drop into either an executable plan (one `move` or\n * `insert` builder action → one operations command → one undo step) or a\n * structured rejection the UI shows *during* the drag. Pure: same inputs,\n * same answer, on both surfaces.\n */\nexport function resolveDrop(args: {\n root: ComponentNode\n getManifest: ManifestLookup\n subject: DragSubject\n location: DropLocation\n}): DropResolution {\n const { root, getManifest, subject, location } = args\n\n if (subject.kind === 'node' && subject.nodeId === root.id) {\n return rejected('root', 'The page root cannot be moved.')\n }\n\n const reference = getNode(root, location.nodeId)\n if (!reference) {\n return rejected('missing-target', `Node \"${location.nodeId}\" is not on this page.`)\n }\n\n // EC-162: dropping beside the reference wraps both in a two-column Grid.\n if (location.position === 'left' || location.position === 'right') {\n return resolveWrap({ root, getManifest, subject, reference, side: location.position })\n }\n\n // Resolve the concrete insertion point: parent node, slot, index.\n let parentId: string\n let slotRule: SlotRule | undefined\n let slotName: string\n let index: number\n\n if (location.position === 'into') {\n const manifest = getManifest(reference.componentId)\n const slot = primaryInsertSlot(manifest)\n if (!slot) {\n return rejected('no-slot', `\"${reference.componentId}\" does not accept children.`)\n }\n parentId = reference.id\n slotRule = slot\n slotName = slot.name\n index = (reference.slots?.[slot.name] ?? []).length\n } else {\n const info = getParentInfo(root, reference.id)\n if (!info) {\n return rejected('root', 'Nothing can be dropped beside the page root.')\n }\n parentId = info.parent.id\n slotName = info.slot\n // Unknown parent manifests impose no allow-list; validation owns that issue.\n slotRule = getManifest(info.parent.componentId)?.slots.find((s) => s.name === info.slot)\n index = info.index + (location.position === 'after' ? 1 : 0)\n }\n\n if (!slotAllows(slotRule, subject.componentId)) {\n return rejected(\n 'not-allowed',\n `Slot \"${slotName}\" does not allow \"${subject.componentId}\".`,\n )\n }\n\n const target: InsertTarget = { parentId, slot: slotName, index }\n\n if (subject.kind === 'component') {\n return { eligible: true, kind: 'insert', target }\n }\n\n // Cycle prevention: a node can never land inside its own subtree.\n if (subject.nodeId === parentId || isDescendantOf(root, subject.nodeId, parentId)) {\n return rejected('own-subtree', 'A node cannot be dropped into its own subtree.')\n }\n\n // No-op detection: the final position (after same-slot removal compensation,\n // matching `moveNode`) equals the node's current position.\n const current = getParentInfo(root, subject.nodeId)\n if (current && current.parent.id === parentId && current.slot === slotName) {\n const finalIndex = index > current.index ? index - 1 : index\n if (finalIndex === current.index) {\n return rejected('no-op', 'Dropping here would not move the node.')\n }\n }\n\n return { eligible: true, kind: 'move', nodeId: subject.nodeId, target }\n}\n\n// ---------------------------------------------------------------------------\n// Wrap gesture (EC-162): drop beside → two-column Grid container\n// ---------------------------------------------------------------------------\n\n/**\n * The container a \"drop beside\" gesture creates. Canonical choice (EC-161\n * semantics): a `Grid` with two columns, **not** a horizontal `Stack` —\n * EC-161 gives `Grid` the canonical column vocabulary (`columns` is a\n * validated graph value the contextual inspector refines from 2 → n), while\n * a horizontal Stack expresses flow order, not column tracks. The values\n * mirror the Grid manifest defaults (`columns: 2`, `gap: '4'`), so the\n * gesture's graph is exactly what composing the same layout manually would\n * produce.\n */\nexport const WRAP_GRID_OPTIONS: GridContainerOptions = { columns: 2, gap: '4' }\n\n/** Eligibility for a `left`/`right` (wrap-beside) drop. */\nfunction resolveWrap(args: {\n root: ComponentNode\n getManifest: ManifestLookup\n subject: DragSubject\n reference: ComponentNode\n side: WrapSide\n}): DropResolution {\n const { root, getManifest, subject, reference, side } = args\n\n // The Grid takes the reference's place in its parent slot — so the\n // reference needs a parent (the root is the page anchor, never wrapped)\n // and that slot's allow-list must accept a Grid.\n const info = getParentInfo(root, reference.id)\n if (!info) {\n return rejected('root', 'The page root cannot be wrapped in a container.')\n }\n const parentSlotRule = getManifest(info.parent.componentId)?.slots.find(\n (s) => s.name === info.slot,\n )\n if (!slotAllows(parentSlotRule, GRID_COMPONENT_ID)) {\n return rejected('not-allowed', `Slot \"${info.slot}\" does not allow a Grid container.`)\n }\n\n // Both columns land in the Grid's children slot.\n const gridSlot = primaryInsertSlot(getManifest(GRID_COMPONENT_ID))\n for (const componentId of [reference.componentId, subject.componentId]) {\n if (!slotAllows(gridSlot, componentId)) {\n return rejected('not-allowed', `A Grid container does not allow \"${componentId}\".`)\n }\n }\n\n if (subject.kind === 'component') {\n return { eligible: true, kind: 'wrap', referenceId: reference.id, side }\n }\n if (subject.nodeId === reference.id) {\n return rejected('no-op', 'A node cannot be placed beside itself.')\n }\n // The reference must not live inside the dragged subtree (the subject is\n // lifted out first — taking the reference with it would orphan the wrap).\n if (isDescendantOf(root, subject.nodeId, reference.id)) {\n return rejected('own-subtree', 'A node cannot wrap an element of its own subtree.')\n }\n return { eligible: true, kind: 'wrap', referenceId: reference.id, side, nodeId: subject.nodeId }\n}\n\n/** What lands beside the reference: an existing node (moved) or a built subtree (inserted). */\nexport type WrapPartner =\n | { kind: 'node'; nodeId: string }\n | { kind: 'subtree'; node: ComponentNode }\n\nexport interface WrapResult {\n root: ComponentNode\n /** The id of the created Grid container. */\n containerId: string\n}\n\n/**\n * Execute a wrap plan as **one** structural edit: lift the partner out of the\n * tree (when it is an existing node) and replace the reference with\n * `gridContainerNode(containerId, WRAP_GRID_OPTIONS, [left, right])` in a\n * single pass. The caller commits the result as one builder action → one\n * operations command → one undo step; EC-161 normalization then runs on the\n * *committed* tree, so the two-child container can never be observed (or\n * persisted) in a half-built state. Returns `null` for structurally invalid\n * input (missing nodes, root reference, reference inside the partner).\n *\n * Determinism (EC-162): the produced container subtree is exactly the\n * `gridContainerNode` constructor output — identical to manual composition.\n */\nexport function applyWrap(args: {\n root: ComponentNode\n referenceId: string\n side: WrapSide\n partner: WrapPartner\n containerId: string\n}): WrapResult | null {\n const { root, referenceId, side, partner, containerId } = args\n if (referenceId === root.id || !getNode(root, referenceId)) return null\n\n let working = root\n let partnerNode: ComponentNode\n if (partner.kind === 'node') {\n if (partner.nodeId === referenceId || partner.nodeId === root.id) return null\n const node = getNode(root, partner.nodeId)\n if (!node || isDescendantOf(root, partner.nodeId, referenceId)) return null\n partnerNode = node\n working = removeNode(root, partner.nodeId)\n } else {\n partnerNode = partner.node\n }\n\n const next = updateNode(working, referenceId, (reference) =>\n gridContainerNode(\n containerId,\n WRAP_GRID_OPTIONS,\n side === 'left' ? [partnerNode, reference] : [reference, partnerNode],\n ),\n )\n return { root: next, containerId }\n}\n\n// ---------------------------------------------------------------------------\n// Pointer → position bands (shared hit-testing model)\n// ---------------------------------------------------------------------------\n\n/** The axis along which a container lays out its children. */\nexport type FlowAxis = 'vertical' | 'horizontal'\n\nfunction staticPropValue(node: ComponentNode, name: string): unknown {\n const prop = node.props?.[name]\n return prop?.kind === 'static' ? prop.value : undefined\n}\n\n/**\n * The flow axis of a container — the axis its children stack along, and\n * therefore the hit-band axis for drops over those children (EC-162 ledger\n * fix: bands follow the parent's flow direction, on both surfaces). Mirrors\n * the renderer: a horizontal Stack flows horizontally; a Grid flows\n * horizontally when it actually has ≥ 2 column tracks (an absent/invalid\n * `columns` renders one column). Everything else is block flow (vertical).\n */\nexport function containerFlowAxis(node: ComponentNode | undefined): FlowAxis {\n if (!node) return 'vertical'\n if (node.componentId === STACK_COMPONENT_ID) {\n return staticPropValue(node, 'direction') === 'horizontal' ? 'horizontal' : 'vertical'\n }\n if (node.componentId === GRID_COMPONENT_ID) {\n const columns = staticPropValue(node, 'columns')\n return typeof columns === 'number' && columns >= 2 ? 'horizontal' : 'vertical'\n }\n return 'vertical'\n}\n\n/** Cross-axis side-band width (fraction of the box) that triggers the wrap gesture. */\nconst WRAP_BAND = 0.18\n\n/**\n * Map a 2D pointer offset within a drop target's box onto a `DropPosition`\n * (EC-162). `flow` is the flow axis of the target's *parent* — before/after\n * bands run along it. On vertically flowing targets, narrow side bands on the\n * cross axis produce `left`/`right` (the wrap-into-columns gesture, when\n * `wrappable`); children of horizontal containers get left/right bands for\n * plain reorder instead, so \"beside\" already means before/after there.\n */\nexport function dropPositionForPoint(args: {\n /** Pointer offset across the target's width, 0..1. */\n x: number\n /** Pointer offset across the target's height, 0..1. */\n y: number\n /** Flow axis of the target's parent (the axis siblings stack along). */\n flow: FlowAxis\n nestable: boolean\n edges: boolean\n /** Enable the wrap side-bands (the gesture surface opts in). */\n wrappable?: boolean\n}): DropPosition {\n const { x, y, flow, nestable, edges, wrappable = false } = args\n if (!edges) return 'into'\n if (wrappable && flow === 'vertical') {\n if (x < WRAP_BAND) return 'left'\n if (x > 1 - WRAP_BAND) return 'right'\n }\n return dropPositionForPointer({ ratio: flow === 'horizontal' ? x : y, nestable, edges })\n}\n\n/**\n * Map a pointer offset within a drop target's box onto a `DropPosition`.\n * `ratio` is the pointer's offset along the target's main axis, 0..1 — the\n * caller picks the axis (the parent's flow axis; see `containerFlowAxis`).\n *\n * - nestable targets with siblings: edge quarters insert before/after, the\n * middle half nests into the slot\n * - leaf targets: top/bottom halves insert before/after\n * - targets without siblings (the root): always `into`\n */\nexport function dropPositionForPointer(args: {\n ratio: number\n /** Whether `into` is structurally possible (target declares an insert slot). */\n nestable: boolean\n /** Whether before/after exist (target has a parent slot). */\n edges: boolean\n}): DropPosition {\n const { ratio, nestable, edges } = args\n if (!edges) return 'into'\n if (nestable) {\n if (ratio < 0.25) return 'before'\n if (ratio > 0.75) return 'after'\n return 'into'\n }\n return ratio < 0.5 ? 'before' : 'after'\n}\n\n// ---------------------------------------------------------------------------\n// Indicator state (shared visual contract)\n// ---------------------------------------------------------------------------\n\n/**\n * The visual state a surface shows for the current resolution. `blocked` is\n * the explicit rejection state (never a silent failed drop); `null` means show\n * nothing (a no-op drop is inert, not an error).\n */\nexport type DropIndicator = DropPosition | 'blocked' | null\n\nexport function dropIndicatorFor(\n resolution: DropResolution,\n position: DropPosition,\n): DropIndicator {\n if (resolution.eligible) return position\n return resolution.code === 'no-op' ? null : 'blocked'\n}\n"]}
1
+ {"version":3,"file":"drop-rules.js","sourceRoot":"","sources":["../../../src/lib/dnd/drop-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,GACX,MAAM,+BAA+B,CAAA;AAmGtC,SAAS,QAAQ,CAAC,IAAuB,EAAE,MAAc;IACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAC1C,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAmC;IACnE,IAAI,CAAC,QAAQ;QAA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;IACC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,MAAM,CAAA;IACzB,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,KAAK,GAAG,IAAI;YAAE,OAAO,QAAQ,CAAA;QACjC,IAAI,KAAK,GAAG,IAAI;YAAE,OAAO,OAAO,CAAA;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAA;AACzC,CAAC;AAaD,MAAM,UAAU,gBAAgB,CAC9B,UAA0B,EAC1B,QAAsB;IAEtB,IAAI,UAAU,CAAC,QAAQ;QAAE,OAAO,QAAQ,CAAA;IACxC,OAAO,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACvD,CAAC","sourcesContent":["import {\n DEFAULT_SLOT,\n GRID_COMPONENT_ID,\n OUTLET_SLOT,\n STACK_COMPONENT_ID,\n getNode,\n getParentInfo,\n gridContainerNode,\n isDescendantOf,\n isStaticProp,\n removeNode,\n updateNode,\n} from '@elytracms/core/project-graph'\nimport type { ComponentNode, GridContainerOptions, InsertTarget } from '@elytracms/core/project-graph'\n\n/**\n * Drag & drop eligibility rules (EC-160 + EC-162, vision §3.1) — pure\n * graph-level functions with **no DOM or UI dependencies**. The canvas and the\n * page tree both resolve drops through `resolveDrop`, so the two surfaces can\n * never disagree about what a manifest slot allow-list permits, which children\n * a component accepts, or whether a move would create a cycle.\n *\n * The drop-zone model is position-based: `into` a slot, `before`/`after` a\n * sibling along the parent's flow axis, and the EC-162 gesture positions\n * `left`/`right` — dropping *beside* an element wraps both in a two-column\n * `Grid` container (see `applyWrap`).\n */\n\n// ---------------------------------------------------------------------------\n// Inputs\n// ---------------------------------------------------------------------------\n\n/**\n * The manifest slice the rules evaluate. Structural (not the full\n * `ComponentManifest`) so tests and future callers can feed minimal lookups.\n */\nexport interface SlotRule {\n name: string\n /** Restrict which component ids may be inserted (omit to allow any). */\n allow?: string[]\n}\n\nexport interface ManifestRules {\n slots: SlotRule[]\n}\n\n/** Resolve a component id to its manifest slot rules (undefined = unknown component). */\nexport type ManifestLookup = (componentId: string) => ManifestRules | undefined\n\n/** What is being dragged. */\nexport type DragSubject =\n /** An existing node of the current page — a completed drop is a `move`. */\n | { kind: 'node'; nodeId: string; componentId: string }\n /** A new subtree (blocks-panel tile) — a completed drop is an `insert`. */\n | { kind: 'component'; componentId: string }\n\n/**\n * Where, relative to a reference node, the drop would land. `into`, `before`\n * and `after` are the EC-160 positions; `left`/`right` are the EC-162 gesture\n * positions — \"beside\" the reference, wrapping both elements in a two-column\n * `Grid` container.\n */\nexport type DropPosition = 'into' | 'before' | 'after' | 'left' | 'right'\n\n/** The side of the reference an EC-162 wrap gesture drops on. */\nexport type WrapSide = 'left' | 'right'\n\nexport interface DropLocation {\n /** The reference node id (the hovered node/row). */\n nodeId: string\n position: DropPosition\n}\n\n// ---------------------------------------------------------------------------\n// Outcomes\n// ---------------------------------------------------------------------------\n\nexport type DropRejectionCode =\n /** The reference node does not exist in the tree. */\n | 'missing-target'\n /** `into` on a component that declares no insertable slot. */\n | 'no-slot'\n /** The target slot's manifest allow-list rejects the dragged component. */\n | 'not-allowed'\n /** Moving a node into itself or its own subtree (cycle). */\n | 'own-subtree'\n /** The page root cannot be moved, and nothing can drop beside it. */\n | 'root'\n /** Structurally valid but changes nothing (dropping a node onto its own position). */\n | 'no-op'\n\nexport interface DropRejection {\n eligible: false\n code: DropRejectionCode\n reason: string\n}\n\n/** An eligible drop: exactly one builder action (move, insert, or wrap) commits it. */\nexport type DropPlan =\n | { eligible: true; kind: 'move'; nodeId: string; target: InsertTarget }\n | { eligible: true; kind: 'insert'; target: InsertTarget }\n /**\n * EC-162 wrap gesture: the reference node and the dragged subject become the\n * two columns of a new `Grid` container, created atomically (`applyWrap`).\n * `nodeId` is present when the subject is an existing node (a move-wrap);\n * absent for blocks-panel components (an insert-wrap via `buildNode`).\n */\n | { eligible: true; kind: 'wrap'; referenceId: string; side: WrapSide; nodeId?: string }\n\nexport type DropResolution = DropPlan | DropRejection\n\nfunction rejected(code: DropRejectionCode, reason: string): DropRejection {\n return { eligible: false, code, reason }\n}\n\n// ---------------------------------------------------------------------------\n// Slot rules\n// ---------------------------------------------------------------------------\n\n/**\n * The slot an `into` drop inserts into: the default `children` slot when\n * declared, else the first authored slot that is not the layout `outlet`.\n * Mirrors the shell's insert-context resolution so click-insert and\n * drag-insert land in the same place.\n */\nexport function primaryInsertSlot(manifest: ManifestRules | undefined): SlotRule | undefined {\n if (!manifest) return undefined\n return (\n manifest.slots.find((s) => s.name === DEFAULT_SLOT) ??\n manifest.slots.find((s) => s.name !== OUTLET_SLOT)\n )\n}\n\n/** True when a component can receive `into` drops at all (declares an insertable slot). */\nexport function canNestInto(getManifest: ManifestLookup, componentId: string): boolean {\n return primaryInsertSlot(getManifest(componentId)) !== undefined\n}\n\n/** True when a slot's allow-list (if any) permits the component id. */\nexport function slotAllows(slot: SlotRule | undefined, componentId: string): boolean {\n if (!slot?.allow) return true\n return slot.allow.includes(componentId)\n}\n\n// ---------------------------------------------------------------------------\n// Resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve a prospective drop into either an executable plan (one `move` or\n * `insert` builder action → one operations command → one undo step) or a\n * structured rejection the UI shows *during* the drag. Pure: same inputs,\n * same answer, on both surfaces.\n */\nexport function resolveDrop(args: {\n root: ComponentNode\n getManifest: ManifestLookup\n subject: DragSubject\n location: DropLocation\n}): DropResolution {\n const { root, getManifest, subject, location } = args\n\n if (subject.kind === 'node' && subject.nodeId === root.id) {\n return rejected('root', 'The page root cannot be moved.')\n }\n\n const reference = getNode(root, location.nodeId)\n if (!reference) {\n return rejected('missing-target', `Node \"${location.nodeId}\" is not on this page.`)\n }\n\n // EC-162: dropping beside the reference wraps both in a two-column Grid.\n if (location.position === 'left' || location.position === 'right') {\n return resolveWrap({ root, getManifest, subject, reference, side: location.position })\n }\n\n // Resolve the concrete insertion point: parent node, slot, index.\n let parentId: string\n let slotRule: SlotRule | undefined\n let slotName: string\n let index: number\n\n if (location.position === 'into') {\n const manifest = getManifest(reference.componentId)\n const slot = primaryInsertSlot(manifest)\n if (!slot) {\n return rejected('no-slot', `\"${reference.componentId}\" does not accept children.`)\n }\n parentId = reference.id\n slotRule = slot\n slotName = slot.name\n index = (reference.slots?.[slot.name] ?? []).length\n } else {\n const info = getParentInfo(root, reference.id)\n if (!info) {\n return rejected('root', 'Nothing can be dropped beside the page root.')\n }\n parentId = info.parent.id\n slotName = info.slot\n // Unknown parent manifests impose no allow-list; validation owns that issue.\n slotRule = getManifest(info.parent.componentId)?.slots.find((s) => s.name === info.slot)\n index = info.index + (location.position === 'after' ? 1 : 0)\n }\n\n if (!slotAllows(slotRule, subject.componentId)) {\n return rejected(\n 'not-allowed',\n `Slot \"${slotName}\" does not allow \"${subject.componentId}\".`,\n )\n }\n\n const target: InsertTarget = { parentId, slot: slotName, index }\n\n if (subject.kind === 'component') {\n return { eligible: true, kind: 'insert', target }\n }\n\n // Cycle prevention: a node can never land inside its own subtree.\n if (subject.nodeId === parentId || isDescendantOf(root, subject.nodeId, parentId)) {\n return rejected('own-subtree', 'A node cannot be dropped into its own subtree.')\n }\n\n // No-op detection: the final position (after same-slot removal compensation,\n // matching `moveNode`) equals the node's current position.\n const current = getParentInfo(root, subject.nodeId)\n if (current && current.parent.id === parentId && current.slot === slotName) {\n const finalIndex = index > current.index ? index - 1 : index\n if (finalIndex === current.index) {\n return rejected('no-op', 'Dropping here would not move the node.')\n }\n }\n\n return { eligible: true, kind: 'move', nodeId: subject.nodeId, target }\n}\n\n// ---------------------------------------------------------------------------\n// Wrap gesture (EC-162): drop beside → two-column Grid container\n// ---------------------------------------------------------------------------\n\n/**\n * The container a \"drop beside\" gesture creates. Canonical choice (EC-161\n * semantics): a `Grid` with two columns, **not** a horizontal `Stack` —\n * EC-161 gives `Grid` the canonical column vocabulary (`columns` is a\n * validated graph value the contextual inspector refines from 2 → n), while\n * a horizontal Stack expresses flow order, not column tracks. The values\n * mirror the Grid manifest defaults (`columns: 2`, `gap: '4'`), so the\n * gesture's graph is exactly what composing the same layout manually would\n * produce.\n */\nexport const WRAP_GRID_OPTIONS: GridContainerOptions = { columns: 2, gap: '4' }\n\n/** Eligibility for a `left`/`right` (wrap-beside) drop. */\nfunction resolveWrap(args: {\n root: ComponentNode\n getManifest: ManifestLookup\n subject: DragSubject\n reference: ComponentNode\n side: WrapSide\n}): DropResolution {\n const { root, getManifest, subject, reference, side } = args\n\n // The Grid takes the reference's place in its parent slot — so the\n // reference needs a parent (the root is the page anchor, never wrapped)\n // and that slot's allow-list must accept a Grid.\n const info = getParentInfo(root, reference.id)\n if (!info) {\n return rejected('root', 'The page root cannot be wrapped in a container.')\n }\n const parentSlotRule = getManifest(info.parent.componentId)?.slots.find(\n (s) => s.name === info.slot,\n )\n if (!slotAllows(parentSlotRule, GRID_COMPONENT_ID)) {\n return rejected('not-allowed', `Slot \"${info.slot}\" does not allow a Grid container.`)\n }\n\n // Both columns land in the Grid's children slot.\n const gridSlot = primaryInsertSlot(getManifest(GRID_COMPONENT_ID))\n for (const componentId of [reference.componentId, subject.componentId]) {\n if (!slotAllows(gridSlot, componentId)) {\n return rejected('not-allowed', `A Grid container does not allow \"${componentId}\".`)\n }\n }\n\n if (subject.kind === 'component') {\n return { eligible: true, kind: 'wrap', referenceId: reference.id, side }\n }\n if (subject.nodeId === reference.id) {\n return rejected('no-op', 'A node cannot be placed beside itself.')\n }\n // The reference must not live inside the dragged subtree (the subject is\n // lifted out first — taking the reference with it would orphan the wrap).\n if (isDescendantOf(root, subject.nodeId, reference.id)) {\n return rejected('own-subtree', 'A node cannot wrap an element of its own subtree.')\n }\n return { eligible: true, kind: 'wrap', referenceId: reference.id, side, nodeId: subject.nodeId }\n}\n\n/** What lands beside the reference: an existing node (moved) or a built subtree (inserted). */\nexport type WrapPartner =\n | { kind: 'node'; nodeId: string }\n | { kind: 'subtree'; node: ComponentNode }\n\nexport interface WrapResult {\n root: ComponentNode\n /** The id of the created Grid container. */\n containerId: string\n}\n\n/**\n * Execute a wrap plan as **one** structural edit: lift the partner out of the\n * tree (when it is an existing node) and replace the reference with\n * `gridContainerNode(containerId, WRAP_GRID_OPTIONS, [left, right])` in a\n * single pass. The caller commits the result as one builder action → one\n * operations command → one undo step; EC-161 normalization then runs on the\n * *committed* tree, so the two-child container can never be observed (or\n * persisted) in a half-built state. Returns `null` for structurally invalid\n * input (missing nodes, root reference, reference inside the partner).\n *\n * Determinism (EC-162): the produced container subtree is exactly the\n * `gridContainerNode` constructor output — identical to manual composition.\n */\nexport function applyWrap(args: {\n root: ComponentNode\n referenceId: string\n side: WrapSide\n partner: WrapPartner\n containerId: string\n}): WrapResult | null {\n const { root, referenceId, side, partner, containerId } = args\n if (referenceId === root.id || !getNode(root, referenceId)) return null\n\n let working = root\n let partnerNode: ComponentNode\n if (partner.kind === 'node') {\n if (partner.nodeId === referenceId || partner.nodeId === root.id) return null\n const node = getNode(root, partner.nodeId)\n if (!node || isDescendantOf(root, partner.nodeId, referenceId)) return null\n partnerNode = node\n working = removeNode(root, partner.nodeId)\n } else {\n partnerNode = partner.node\n }\n\n const next = updateNode(working, referenceId, (reference) =>\n gridContainerNode(\n containerId,\n WRAP_GRID_OPTIONS,\n side === 'left' ? [partnerNode, reference] : [reference, partnerNode],\n ),\n )\n return { root: next, containerId }\n}\n\n// ---------------------------------------------------------------------------\n// Pointer → position bands (shared hit-testing model)\n// ---------------------------------------------------------------------------\n\n/** The axis along which a container lays out its children. */\nexport type FlowAxis = 'vertical' | 'horizontal'\n\nfunction staticPropValue(node: ComponentNode, name: string): unknown {\n const prop = node.props?.[name]\n return isStaticProp(prop) ? prop.value : undefined\n}\n\n/**\n * The flow axis of a container — the axis its children stack along, and\n * therefore the hit-band axis for drops over those children (EC-162 ledger\n * fix: bands follow the parent's flow direction, on both surfaces). Mirrors\n * the renderer: a horizontal Stack flows horizontally; a Grid flows\n * horizontally when it actually has ≥ 2 column tracks (an absent/invalid\n * `columns` renders one column). Everything else is block flow (vertical).\n */\nexport function containerFlowAxis(node: ComponentNode | undefined): FlowAxis {\n if (!node) return 'vertical'\n if (node.componentId === STACK_COMPONENT_ID) {\n return staticPropValue(node, 'direction') === 'horizontal' ? 'horizontal' : 'vertical'\n }\n if (node.componentId === GRID_COMPONENT_ID) {\n const columns = staticPropValue(node, 'columns')\n return typeof columns === 'number' && columns >= 2 ? 'horizontal' : 'vertical'\n }\n return 'vertical'\n}\n\n/** Cross-axis side-band width (fraction of the box) that triggers the wrap gesture. */\nconst WRAP_BAND = 0.18\n\n/**\n * Map a 2D pointer offset within a drop target's box onto a `DropPosition`\n * (EC-162). `flow` is the flow axis of the target's *parent* — before/after\n * bands run along it. On vertically flowing targets, narrow side bands on the\n * cross axis produce `left`/`right` (the wrap-into-columns gesture, when\n * `wrappable`); children of horizontal containers get left/right bands for\n * plain reorder instead, so \"beside\" already means before/after there.\n */\nexport function dropPositionForPoint(args: {\n /** Pointer offset across the target's width, 0..1. */\n x: number\n /** Pointer offset across the target's height, 0..1. */\n y: number\n /** Flow axis of the target's parent (the axis siblings stack along). */\n flow: FlowAxis\n nestable: boolean\n edges: boolean\n /** Enable the wrap side-bands (the gesture surface opts in). */\n wrappable?: boolean\n}): DropPosition {\n const { x, y, flow, nestable, edges, wrappable = false } = args\n if (!edges) return 'into'\n if (wrappable && flow === 'vertical') {\n if (x < WRAP_BAND) return 'left'\n if (x > 1 - WRAP_BAND) return 'right'\n }\n return dropPositionForPointer({ ratio: flow === 'horizontal' ? x : y, nestable, edges })\n}\n\n/**\n * Map a pointer offset within a drop target's box onto a `DropPosition`.\n * `ratio` is the pointer's offset along the target's main axis, 0..1 — the\n * caller picks the axis (the parent's flow axis; see `containerFlowAxis`).\n *\n * - nestable targets with siblings: edge quarters insert before/after, the\n * middle half nests into the slot\n * - leaf targets: top/bottom halves insert before/after\n * - targets without siblings (the root): always `into`\n */\nexport function dropPositionForPointer(args: {\n ratio: number\n /** Whether `into` is structurally possible (target declares an insert slot). */\n nestable: boolean\n /** Whether before/after exist (target has a parent slot). */\n edges: boolean\n}): DropPosition {\n const { ratio, nestable, edges } = args\n if (!edges) return 'into'\n if (nestable) {\n if (ratio < 0.25) return 'before'\n if (ratio > 0.75) return 'after'\n return 'into'\n }\n return ratio < 0.5 ? 'before' : 'after'\n}\n\n// ---------------------------------------------------------------------------\n// Indicator state (shared visual contract)\n// ---------------------------------------------------------------------------\n\n/**\n * The visual state a surface shows for the current resolution. `blocked` is\n * the explicit rejection state (never a silent failed drop); `null` means show\n * nothing (a no-op drop is inert, not an error).\n */\nexport type DropIndicator = DropPosition | 'blocked' | null\n\nexport function dropIndicatorFor(\n resolution: DropResolution,\n position: DropPosition,\n): DropIndicator {\n if (resolution.eligible) return position\n return resolution.code === 'no-op' ? null : 'blocked'\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { SPACING_TOKEN_CSS, SPACING_TOKEN_NAMES, isSpacingTokenName, spacingTokenFromLegacyGap, } from '@elytracms/core/project-graph';
1
+ import { SPACING_TOKEN_CSS, SPACING_TOKEN_NAMES, isSpacingTokenName, isStaticProp, spacingTokenFromLegacyGap, } from '@elytracms/core/project-graph';
2
2
  /** The full drag range, smallest to largest: none, then the EC-161 token scale. */
3
3
  export const GAP_STEPS = [null, ...SPACING_TOKEN_NAMES];
4
4
  /** Canvas root font size — the deterministic rem basis for token CSS lengths. */
@@ -45,7 +45,7 @@ export function gapStepFromDrag(start, deltaPx) {
45
45
  */
46
46
  export function containerGapStep(node) {
47
47
  const prop = node.props?.['gap'];
48
- if (prop?.kind !== 'static')
48
+ if (!isStaticProp(prop))
49
49
  return null;
50
50
  if (typeof prop.value === 'string' && isSpacingTokenName(prop.value))
51
51
  return prop.value;
@@ -1 +1 @@
1
- {"version":3,"file":"gap-drag.js","sourceRoot":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V,WAAW,EAAE,QAAQ,GAAG,UAAU;SACnC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {\n SPACING_TOKEN_CSS,\n SPACING_TOKEN_NAMES,\n isSpacingTokenName,\n spacingTokenFromLegacyGap,\n} from '@elytracms/core/project-graph'\nimport type { ComponentNode, SpacingTokenName } from '@elytracms/core/project-graph'\nimport type { FlowAxis } from './drop-rules'\n\n/**\n * Tokenized gap-drag math (EC-163, vision §3.1 / AD-10) — pure functions with\n * no DOM dependencies, shared by the canvas spacing handles. The drag model is\n * deliberately token-quantized: a pointer delta moves the gap through the\n * EC-161 spacing-token *steps*, and the only values that can ever be produced\n * are a `SpacingTokenName` or `null` (\"no gap\" — the prop is removed, exactly\n * what the layout inspector's \"None\" choice does). No freeform pixel value can\n * leave this module, so none can enter the graph from the canvas.\n */\n\n/** A gap step the drag can land on: a spacing token, or `null` for \"no gap\". */\nexport type GapStep = SpacingTokenName | null\n\n/** The full drag range, smallest to largest: none, then the EC-161 token scale. */\nexport const GAP_STEPS: readonly GapStep[] = [null, ...SPACING_TOKEN_NAMES]\n\n/** Canvas root font size — the deterministic rem basis for token CSS lengths. */\nexport const GAP_REM_PX = 16\n\n/** The pixel length of a gap step at the canvas rem basis. */\nexport function gapStepPx(step: GapStep): number {\n if (step === null) return 0\n const css = SPACING_TOKEN_CSS[step]\n const value = Number.parseFloat(css)\n return css.endsWith('rem') ? value * GAP_REM_PX : value\n}\n\n/** The CSS length a previewed step renders with (the same length the renderer emits). */\nexport function gapStepCss(step: GapStep): string {\n return step === null ? '0px' : SPACING_TOKEN_CSS[step]\n}\n\n/** Snap a raw pixel gap onto the nearest step of the token scale. */\nexport function nearestGapStep(px: number): GapStep {\n let best: GapStep = null\n let bestDistance = Number.POSITIVE_INFINITY\n for (const step of GAP_STEPS) {\n const distance = Math.abs(gapStepPx(step) - px)\n if (distance < bestDistance) {\n bestDistance = distance\n best = step\n }\n }\n return best\n}\n\n/**\n * The step a drag lands on: the starting step's pixel length plus the pointer\n * delta along the container's flow axis, snapped to the scale. Monotonic and\n * deterministic — the same delta from the same start always lands on the same\n * token.\n */\nexport function gapStepFromDrag(start: GapStep, deltaPx: number): GapStep {\n return nearestGapStep(gapStepPx(start) + deltaPx)\n}\n\n/**\n * The current gap step of a container node: a token name verbatim, a legacy\n * on-scale integer mapped to its token, anything else (absent, off-scale,\n * bound) as `null` — mirroring how the layout inspector reads the same prop,\n * so handle and inspector always start from the same value.\n */\nexport function containerGapStep(node: ComponentNode): GapStep {\n const prop = node.props?.['gap']\n if (prop?.kind !== 'static') return null\n if (typeof prop.value === 'string' && isSpacingTokenName(prop.value)) return prop.value\n if (typeof prop.value === 'number') {\n const token = spacingTokenFromLegacyGap(prop.value)\n if (token) return token\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Handle geometry — where the between-children handles sit\n// ---------------------------------------------------------------------------\n\n/** A minimal rectangle (client or document coordinates — caller's choice). */\nexport interface GapRect {\n left: number\n top: number\n width: number\n height: number\n}\n\n/**\n * One draggable spot between two adjacent children. `x`/`y` is the gap's\n * center point; `crossStart`/`crossLength` span the children's shared extent\n * on the cross axis (the handle's visible length).\n */\nexport interface GapHandleSpot {\n /** Index of the leading child of the pair. */\n index: number\n x: number\n y: number\n crossStart: number\n crossLength: number\n}\n\n/**\n * The handle spots between consecutive child rects along the container's flow\n * axis. Pairs that wrap (grid rows: the next rect starts before the previous\n * ends along the axis) or that do not overlap on the cross axis yield no\n * handle — handles only ever sit in real gaps between visual neighbours.\n * Works at gap 0 too: the handle sits on the shared boundary so a closed gap\n * can be dragged open.\n */\nexport function gapHandleSpots(rects: readonly GapRect[], axis: FlowAxis): GapHandleSpot[] {\n const spots: GapHandleSpot[] = []\n for (let i = 0; i < rects.length - 1; i += 1) {\n const a = rects[i]!\n const b = rects[i + 1]!\n const aEnd = axis === 'horizontal' ? a.left + a.width : a.top + a.height\n const bStart = axis === 'horizontal' ? b.left : b.top\n // Wrapped to the next row/column: not visual neighbours along the axis.\n // A small tolerance keeps sub-pixel layout from dropping legitimate pairs.\n if (bStart < aEnd - 0.5) continue\n const crossStart = axis === 'horizontal' ? Math.max(a.top, b.top) : Math.max(a.left, b.left)\n const crossEnd =\n axis === 'horizontal'\n ? Math.min(a.top + a.height, b.top + b.height)\n : Math.min(a.left + a.width, b.left + b.width)\n if (crossEnd <= crossStart) continue\n const mid = (aEnd + bStart) / 2\n spots.push({\n index: i,\n x: axis === 'horizontal' ? mid : crossStart + (crossEnd - crossStart) / 2,\n y: axis === 'horizontal' ? crossStart + (crossEnd - crossStart) / 2 : mid,\n crossStart,\n crossLength: crossEnd - crossStart,\n })\n }\n return spots\n}\n"]}
1
+ {"version":3,"file":"gap-drag.js","sourceRoot":"","sources":["../../../src/lib/dnd/gap-drag.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,GAC1B,MAAM,+BAA+B,CAAA;AAiBtC,mFAAmF;AACnF,MAAM,CAAC,MAAM,SAAS,GAAuB,CAAC,IAAI,EAAE,GAAG,mBAAmB,CAAC,CAAA;AAE3E,iFAAiF;AACjF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAA;AAE5B,8DAA8D;AAC9D,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,CAAC,CAAA;IAC3B,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACpC,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAA;AACzD,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,IAAI,KAAK,IAAI,CA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AG,CAAC,CAAC,KAAK,CAAC,CAAA;QAClD,IAAI,QAAQ,IAAI,UAAU;YAAE,SAAQ;QACpC,MAAM,GAAG,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QAC/B,KAAK,CAAC,IAAI,CAAC;YACT,KAAK,EAAE,CAAC;YACR,CAAC,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC;YACzE,CAAC,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;YACzE,UAAU;YACV,WAAW,EAAE,QAAQ,GAAG,UAAU;SACnC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {\n SPACING_TOKEN_CSS,\n SPACING_TOKEN_NAMES,\n isSpacingTokenName,\n isStaticProp,\n spacingTokenFromLegacyGap,\n} from '@elytracms/core/project-graph'\nimport type { ComponentNode, SpacingTokenName } from '@elytracms/core/project-graph'\nimport type { FlowAxis } from './drop-rules'\n\n/**\n * Tokenized gap-drag math (EC-163, vision §3.1 / AD-10) — pure functions with\n * no DOM dependencies, shared by the canvas spacing handles. The drag model is\n * deliberately token-quantized: a pointer delta moves the gap through the\n * EC-161 spacing-token *steps*, and the only values that can ever be produced\n * are a `SpacingTokenName` or `null` (\"no gap\" — the prop is removed, exactly\n * what the layout inspector's \"None\" choice does). No freeform pixel value can\n * leave this module, so none can enter the graph from the canvas.\n */\n\n/** A gap step the drag can land on: a spacing token, or `null` for \"no gap\". */\nexport type GapStep = SpacingTokenName | null\n\n/** The full drag range, smallest to largest: none, then the EC-161 token scale. */\nexport const GAP_STEPS: readonly GapStep[] = [null, ...SPACING_TOKEN_NAMES]\n\n/** Canvas root font size — the deterministic rem basis for token CSS lengths. */\nexport const GAP_REM_PX = 16\n\n/** The pixel length of a gap step at the canvas rem basis. */\nexport function gapStepPx(step: GapStep): number {\n if (step === null) return 0\n const css = SPACING_TOKEN_CSS[step]\n const value = Number.parseFloat(css)\n return css.endsWith('rem') ? value * GAP_REM_PX : value\n}\n\n/** The CSS length a previewed step renders with (the same length the renderer emits). */\nexport function gapStepCss(step: GapStep): string {\n return step === null ? '0px' : SPACING_TOKEN_CSS[step]\n}\n\n/** Snap a raw pixel gap onto the nearest step of the token scale. */\nexport function nearestGapStep(px: number): GapStep {\n let best: GapStep = null\n let bestDistance = Number.POSITIVE_INFINITY\n for (const step of GAP_STEPS) {\n const distance = Math.abs(gapStepPx(step) - px)\n if (distance < bestDistance) {\n bestDistance = distance\n best = step\n }\n }\n return best\n}\n\n/**\n * The step a drag lands on: the starting step's pixel length plus the pointer\n * delta along the container's flow axis, snapped to the scale. Monotonic and\n * deterministic — the same delta from the same start always lands on the same\n * token.\n */\nexport function gapStepFromDrag(start: GapStep, deltaPx: number): GapStep {\n return nearestGapStep(gapStepPx(start) + deltaPx)\n}\n\n/**\n * The current gap step of a container node: a token name verbatim, a legacy\n * on-scale integer mapped to its token, anything else (absent, off-scale,\n * bound) as `null` — mirroring how the layout inspector reads the same prop,\n * so handle and inspector always start from the same value.\n */\nexport function containerGapStep(node: ComponentNode): GapStep {\n const prop = node.props?.['gap']\n if (!isStaticProp(prop)) return null\n if (typeof prop.value === 'string' && isSpacingTokenName(prop.value)) return prop.value\n if (typeof prop.value === 'number') {\n const token = spacingTokenFromLegacyGap(prop.value)\n if (token) return token\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Handle geometry — where the between-children handles sit\n// ---------------------------------------------------------------------------\n\n/** A minimal rectangle (client or document coordinates — caller's choice). */\nexport interface GapRect {\n left: number\n top: number\n width: number\n height: number\n}\n\n/**\n * One draggable spot between two adjacent children. `x`/`y` is the gap's\n * center point; `crossStart`/`crossLength` span the children's shared extent\n * on the cross axis (the handle's visible length).\n */\nexport interface GapHandleSpot {\n /** Index of the leading child of the pair. */\n index: number\n x: number\n y: number\n crossStart: number\n crossLength: number\n}\n\n/**\n * The handle spots between consecutive child rects along the container's flow\n * axis. Pairs that wrap (grid rows: the next rect starts before the previous\n * ends along the axis) or that do not overlap on the cross axis yield no\n * handle — handles only ever sit in real gaps between visual neighbours.\n * Works at gap 0 too: the handle sits on the shared boundary so a closed gap\n * can be dragged open.\n */\nexport function gapHandleSpots(rects: readonly GapRect[], axis: FlowAxis): GapHandleSpot[] {\n const spots: GapHandleSpot[] = []\n for (let i = 0; i < rects.length - 1; i += 1) {\n const a = rects[i]!\n const b = rects[i + 1]!\n const aEnd = axis === 'horizontal' ? a.left + a.width : a.top + a.height\n const bStart = axis === 'horizontal' ? b.left : b.top\n // Wrapped to the next row/column: not visual neighbours along the axis.\n // A small tolerance keeps sub-pixel layout from dropping legitimate pairs.\n if (bStart < aEnd - 0.5) continue\n const crossStart = axis === 'horizontal' ? Math.max(a.top, b.top) : Math.max(a.left, b.left)\n const crossEnd =\n axis === 'horizontal'\n ? Math.min(a.top + a.height, b.top + b.height)\n : Math.min(a.left + a.width, b.left + b.width)\n if (crossEnd <= crossStart) continue\n const mid = (aEnd + bStart) / 2\n spots.push({\n index: i,\n x: axis === 'horizontal' ? mid : crossStart + (crossEnd - crossStart) / 2,\n y: axis === 'horizontal' ? crossStart + (crossEnd - crossStart) / 2 : mid,\n crossStart,\n crossLength: crossEnd - crossStart,\n })\n }\n return spots\n}\n"]}
@@ -51,13 +51,22 @@ export declare function resolveStudioI18n(): ResolvedI18n;
51
51
  * is the React-idiomatic wrapper.
52
52
  */
53
53
  export declare function translate(key: string, vars?: Record<string, string | number>): string;
54
+ export declare function msgLabel(key: string): LocalizedString;
55
+ /**
56
+ * Decode a {@link msgLabel} to its translated string for the active locale, or
57
+ * `undefined` when the value is not a catalog-backed label (a plain string / locale
58
+ * map / absent). Every studio label read site checks this first, then falls back to
59
+ * {@link resolveLabel} for ordinary labels.
60
+ */
61
+ export declare function resolveMsgLabel(value: unknown): string | undefined;
54
62
  /**
55
63
  * Resolve a {@link LocalizedString} (field/collection/option label) against the
56
64
  * active UI locale (EC-241) — **non-hook**, reading the per-boot singleton, so it is
57
65
  * safe to call anywhere: a component body, a nested render helper, or config-build
58
66
  * code. Returns `fallback` (default `''`) when the value is absent. Prefer this over
59
67
  * `resolveLabel(x, useUiLocale())` at render sites — it localizes without a hook, so
60
- * it can't trip the rules-of-hooks in a conditional/nested position.
68
+ * it can't trip the rules-of-hooks in a conditional/nested position. A catalog-backed
69
+ * {@link msgLabel} (the built-in rails) resolves through the message catalog.
61
70
  */
62
71
  export declare function localizedLabel(value: LocalizedString | undefined, fallback?: string): string;
63
72
  /** The active studio-UI locale (browser-resolved). */
@@ -97,7 +97,18 @@ export function resolveStudioI18n() {
97
97
  const defaultLocale = config.defaultLocale ?? BUILTIN_DEFAULT_LOCALE;
98
98
  const locales = config.locales ?? {};
99
99
  const available = [defaultLocale, ...Object.keys(locales).filter((l) => l !== defaultLocale)];
100
- const locale = localeOverride ?? resolveActiveLocale(available, navigatorLanguages(), defaultLocale);
100
+ // A config-pinned locale (EC-241) takes precedence over browser detection: it is read
101
+ // from config — identical on server and client — so SSR and hydration agree (no
102
+ // navigator-vs-server split). An unavailable pin is ignored with a visible signal
103
+ // ("failures are first-class"), and detection resumes.
104
+ let pinned;
105
+ if (config.locale !== undefined) {
106
+ if (available.includes(config.locale))
107
+ pinned = config.locale;
108
+ else
109
+ warnOnce(`[i18n] pinned locale "${config.locale}" is not available (default "${defaultLocale}" + ${JSON.stringify(Object.keys(locales))}); using browser detection.`);
110
+ }
111
+ const locale = localeOverride ?? pinned ?? resolveActiveLocale(available, navigatorLanguages(), defaultLocale);
101
112
  const active = locale === defaultLocale ? {} : (locales[locale] ?? {});
102
113
  // Coverage lint: warn once when the active locale doesn't cover every English key.
103
114
  if (locale !== defaultLocale && locales[locale]) {
@@ -127,15 +138,49 @@ export function translate(key, vars) {
127
138
  }
128
139
  return vars ? interpolate(hit, vars) : hit;
129
140
  }
141
+ /**
142
+ * A **catalog-backed** schema label (EC-241): a label whose text comes from the message
143
+ * catalog by `key`, not a hard-coded string or a per-locale map. This is how the
144
+ * engine's own built-in schemas (the redirects/users rails) localize — their default
145
+ * labels resolve through the *same* consumer catalog as the rest of the chrome, so one
146
+ * German catalog covers them with no per-rail override and no per-language data in
147
+ * engine code. Consumers never author these (their labels are plain strings or
148
+ * `{ en, de }` maps); it is an engine-internal seam.
149
+ *
150
+ * Encoded as a sentinel-prefixed string so it is a valid {@link LocalizedString} (no
151
+ * change to the serializable schema type) and survives zod parse / object spread — it
152
+ * is decoded only at the final render site by {@link resolveMsgLabel}. On the delivery
153
+ * side (no catalog) `resolveLabel` returns it verbatim, which is harmless: the built-in
154
+ * rails never render there.
155
+ */
156
+ const MSG_LABEL_SENTINEL = '@@msg:';
157
+ export function msgLabel(key) {
158
+ return MSG_LABEL_SENTINEL + key;
159
+ }
160
+ /**
161
+ * Decode a {@link msgLabel} to its translated string for the active locale, or
162
+ * `undefined` when the value is not a catalog-backed label (a plain string / locale
163
+ * map / absent). Every studio label read site checks this first, then falls back to
164
+ * {@link resolveLabel} for ordinary labels.
165
+ */
166
+ export function resolveMsgLabel(value) {
167
+ return typeof value === 'string' && value.startsWith(MSG_LABEL_SENTINEL)
168
+ ? translate(value.slice(MSG_LABEL_SENTINEL.length))
169
+ : undefined;
170
+ }
130
171
  /**
131
172
  * Resolve a {@link LocalizedString} (field/collection/option label) against the
132
173
  * active UI locale (EC-241) — **non-hook**, reading the per-boot singleton, so it is
133
174
  * safe to call anywhere: a component body, a nested render helper, or config-build
134
175
  * code. Returns `fallback` (default `''`) when the value is absent. Prefer this over
135
176
  * `resolveLabel(x, useUiLocale())` at render sites — it localizes without a hook, so
136
- * it can't trip the rules-of-hooks in a conditional/nested position.
177
+ * it can't trip the rules-of-hooks in a conditional/nested position. A catalog-backed
178
+ * {@link msgLabel} (the built-in rails) resolves through the message catalog.
137
179
  */
138
180
  export function localizedLabel(value, fallback = '') {
181
+ const fromCatalog = resolveMsgLabel(value);
182
+ if (fromCatalog !== undefined)
183
+ return fromCatalog;
139
184
  const { locale, defaultLocale } = resolveStudioI18n();
140
185
  return resolveLabel(value, locale, defaultLocale) ?? fallback;
141
186
  }
@@ -155,7 +200,7 @@ export function useT() {
155
200
  */
156
201
  export function useLabel() {
157
202
  const { locale, defaultLocale } = resolveStudioI18n();
158
- return useMemo(() => (value, fallback) => resolveLabel(value, locale, defaultLocale) ?? fallback ?? '', [locale, defaultLocale]);
203
+ return useMemo(() => (value, fallback) => resolveMsgLabel(value) ?? resolveLabel(value, locale, defaultLocale) ?? fallback ?? '', [locale, defaultLocale]);
159
204
  }
160
205
  /** Test seam: force the active locale. Never used by app code. */
161
206
  export function setUiLocaleForTests(locale) {
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../src/lib/i18n/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C;;;;;;;GAOG;AAEH,MAAM,sBAAsB,GAAG,IAAI,CAAA;AAEnC;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA4B,EAC5B,SAA4B,EAC5B,aAAqB;IAErB,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;IACnD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CA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EAAE,aAAa,CAAC,IAAI,QAAQ,IAAI,EAAE,EACvF,CAAC,MAAM,EAAE,aAAa,CAAC,CACxB,CAAA;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,cAAc,GAAG,MAAM,CAAA;IACvB,MAAM,CAAC,KAAK,EAAE,CAAA;AAChB,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,uBAAuB;IACrC,MAAM,CAAC,KAAK,EAAE,CAAA;IACd,uBAAuB,GAAG,IAAI,CAAA;AAChC,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport { resolveLabel } from '@elytracms/core/cms-core'\nimport type { LocalizedString } from '@elytracms/core/cms-core'\nimport { resolveDeploymentI18n } from '@elytracms/studio/lib/workspace'\nimport { EN_MESSAGES } from './messages.en'\nimport type { MessageCatalog, SourceCatalog } from './types'\n\n/**\n * Studio-UI localization runtime (EC-241). Resolves the active UI locale from the\n * **browser's preferred locale** (no persisted selector in v1 — that rides EC-240's\n * deferred account settings), then translates message keys with an\n * active-locale → English → visible-fallback chain. The studio config is static per\n * boot, so resolution is memoised once (like `getWorkspaceState`); a locale switch\n * needs a reload, which is all v1 offers.\n */\n\nconst BUILTIN_DEFAULT_LOCALE = 'en'\n\n/**\n * Pick the best available locale for the browser's ordered language preferences\n * (EC-241): an exact tag match wins, else the base language (`de-DE` → `de`), else\n * `defaultLocale`. Pure + deterministic — the browser list is the only input.\n */\nexport function resolveActiveLocale(\n available: readonly string[],\n preferred: readonly string[],\n defaultLocale: string,\n): string {\n const lower = available.map((a) => a.toLowerCase())\n for (const pref of preferred) {\n const p = pref.toLowerCase()\n const base = p.split('-')[0] ?? p\n const at = lower.findIndex((a) => a === p || a === base)\n if (at >= 0) return available[at]!\n }\n return defaultLocale\n}\n\ninterface ResolvedI18n {\n locale: string\n defaultLocale: string\n /** The active-locale catalog (empty when active === default → the English source is used). */\n active: MessageCatalog\n source: SourceCatalog\n}\n\nlet localeOverride: string | null = null\n\ntype LanguagesResolver = () => readonly string[] | null | undefined\nlet serverLanguagesResolver: LanguagesResolver | null = null\n\n/**\n * Provide the request's preferred languages for **SSR** (EC-241). The server has no\n * `navigator`, so without this the server renders the default locale while the client\n * renders the browser locale — a hydration mismatch (server text ≠ client text). A\n * host (e.g. the TanStack Start root) sets a resolver that reads the request's\n * `Accept-Language` header. It is invoked per render, so when the host reads from\n * request-scoped storage (TanStack's AsyncLocalStorage) it stays concurrency-safe —\n * the engine keeps no request state. A no-op on the client, where `navigator` wins.\n */\nexport function setServerLanguagesResolver(fn: LanguagesResolver | null): void {\n serverLanguagesResolver = fn\n}\n\n/**\n * Parse an HTTP `Accept-Language` header into an ordered list of language tags,\n * highest q-weight first: `de,en-US;q=0.7,en;q=0.3` → `['de', 'en-US', 'en']`. The\n * server equivalent of `navigator.languages`, so SSR resolves the same locale the\n * client will.\n */\nexport function parseAcceptLanguage(header: string | null | undefined): string[] {\n if (!header) return []\n return header\n .split(',')\n .map((part) => {\n const [tag, ...params] = part.trim().split(';')\n const q = params.map((p) => p.trim()).find((p) => p.startsWith('q='))\n const weight = q ? Number.parseFloat(q.slice(2)) : 1\n return { tag: (tag ?? '').trim(), weight: Number.isFinite(weight) ? weight : 1 }\n })\n .filter((entry) => entry.tag !== '' && entry.tag !== '*')\n .sort((a, b) => b.weight - a.weight)\n .map((entry) => entry.tag)\n}\n\nfunction navigatorLanguages(): string[] {\n if (typeof navigator !== 'undefined') {\n if (navigator.languages && navigator.languages.length > 0) return [...navigator.languages]\n if (navigator.language) return [navigator.language]\n }\n // SSR (no navigator): a host may resolve the request's Accept-Language.\n const server = serverLanguagesResolver?.()\n return server ? [...server] : []\n}\n\nconst warned = new Set<string>()\nfunction warnOnce(message: string): void {\n if (warned.has(message)) return\n warned.add(message)\n if (typeof console !== 'undefined') console.warn(message)\n}\n\n/**\n * Resolve the studio i18n from the config holder + the browser locale (EC-241).\n *\n * NOT cached: the studio config holder (`createStudio`) is seeded at the mount, which\n * runs AFTER the consumer's `studio.config` module built its sidebar — so an eager\n * `translate` during that sidebar build (e.g. a built-in view label) sees an empty\n * config. Caching the first result would poison every later render-time call with\n * that empty-config English. Re-resolving each call is cheap (a few array ops) and\n * always reflects the config once the mount has run. `translate`/`localizedLabel`\n * are the hot callers; built-in view labels are lazy getters so they re-resolve too.\n */\nexport function resolveStudioI18n(): ResolvedI18n {\n const config = resolveDeploymentI18n() ?? {}\n const defaultLocale = config.defaultLocale ?? BUILTIN_DEFAULT_LOCALE\n const locales = config.locales ?? {}\n const available = [defaultLocale, ...Object.keys(locales).filter((l) => l !== defaultLocale)]\n const locale = localeOverride ?? resolveActiveLocale(available, navigatorLanguages(), defaultLocale)\n const active = locale === defaultLocale ? {} : (locales[locale] ?? {})\n // Coverage lint: warn once when the active locale doesn't cover every English key.\n if (locale !== defaultLocale && locales[locale]) {\n const missing = Object.keys(EN_MESSAGES).filter((k) => !(k in active))\n if (missing.length > 0) {\n warnOnce(\n `[i18n] locale \"${locale}\" is missing ${missing.length} message(s); falling back to English for those.`,\n )\n }\n }\n return { locale, defaultLocale, active, source: EN_MESSAGES }\n}\n\nfunction interpolate(text: string, vars: Record<string, string | number>): string {\n return text.replace(/\\{(\\w+)\\}/g, (whole, key: string) => (key in vars ? String(vars[key]) : whole))\n}\n\n/**\n * Translate a message key for the active UI locale (EC-241): active-locale string\n * ?? English source ?? **the key itself** (a visible fallback + a one-time console\n * signal — \"failures are first-class\", never a silent blank). Non-hook — reads the\n * per-boot singleton, so config-build and pure code can localize too; {@link useT}\n * is the React-idiomatic wrapper.\n */\nexport function translate(key: string, vars?: Record<string, string | number>): string {\n const i18n = resolveStudioI18n()\n const hit = i18n.active[key] ?? i18n.source[key]?.message\n if (hit === undefined) {\n warnOnce(`[i18n] missing message key: \"${key}\"`)\n return key\n }\n return vars ? interpolate(hit, vars) : hit\n}\n\n/**\n * Resolve a {@link LocalizedString} (field/collection/option label) against the\n * active UI locale (EC-241) — **non-hook**, reading the per-boot singleton, so it is\n * safe to call anywhere: a component body, a nested render helper, or config-build\n * code. Returns `fallback` (default `''`) when the value is absent. Prefer this over\n * `resolveLabel(x, useUiLocale())` at render sites — it localizes without a hook, so\n * it can't trip the rules-of-hooks in a conditional/nested position.\n */\nexport function localizedLabel(value: LocalizedString | undefined, fallback = ''): string {\n const { locale, defaultLocale } = resolveStudioI18n()\n return resolveLabel(value, locale, defaultLocale) ?? fallback\n}\n\n// --- React hooks ---\n\n/** The active studio-UI locale (browser-resolved). */\nexport function useUiLocale(): string {\n return resolveStudioI18n().locale\n}\n\n/** A `t(key, vars?)` translator bound to the active locale. */\nexport function useT(): (key: string, vars?: Record<string, string | number>) => string {\n return translate\n}\n\n/**\n * Resolve a {@link LocalizedString} label (field/collection/option) for the active\n * locale. Re-reads the locale each render (keyed into the memo) so it never captures\n * a locale resolved before the mount seeded the i18n config.\n */\nexport function useLabel(): (value: LocalizedString | undefined, fallback?: string) => string {\n const { locale, defaultLocale } = resolveStudioI18n()\n return useMemo(\n () => (value, fallback) => resolveLabel(value, locale, defaultLocale) ?? fallback ?? '',\n [locale, defaultLocale],\n )\n}\n\n/** Test seam: force the active locale. Never used by app code. */\nexport function setUiLocaleForTests(locale: string | null): void {\n localeOverride = locale\n warned.clear()\n}\n\n/** Test seam: reset i18n state (once-per-boot warnings + the SSR resolver). Never used by app code. */\nexport function resetStudioI18nForTests(): void {\n warned.clear()\n serverLanguagesResolver = null\n}\n"]}
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../src/lib/i18n/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C;;;;;;;GAOG;AAEH,MAAM,sBAAsB,GAAG,IAAI,CAAA;AAEnC;;;;G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K,EAAE,QAAQ,EAAE,EAAE,CACxB,eAAe,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,IAAI,QAAQ,IAAI,EAAE,EACxF,CAAC,MAAM,EAAE,aAAa,CAAC,CACxB,CAAA;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,cAAc,GAAG,MAAM,CAAA;IACvB,MAAM,CAAC,KAAK,EAAE,CAAA;AAChB,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,uBAAuB;IACrC,MAAM,CAAC,KAAK,EAAE,CAAA;IACd,uBAAuB,GAAG,IAAI,CAAA;AAChC,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport { resolveLabel } from '@elytracms/core/cms-core'\nimport type { LocalizedString } from '@elytracms/core/cms-core'\nimport { resolveDeploymentI18n } from '@elytracms/studio/lib/workspace'\nimport { EN_MESSAGES } from './messages.en'\nimport type { MessageCatalog, SourceCatalog } from './types'\n\n/**\n * Studio-UI localization runtime (EC-241). Resolves the active UI locale from the\n * **browser's preferred locale** (no persisted selector in v1 — that rides EC-240's\n * deferred account settings), then translates message keys with an\n * active-locale → English → visible-fallback chain. The studio config is static per\n * boot, so resolution is memoised once (like `getWorkspaceState`); a locale switch\n * needs a reload, which is all v1 offers.\n */\n\nconst BUILTIN_DEFAULT_LOCALE = 'en'\n\n/**\n * Pick the best available locale for the browser's ordered language preferences\n * (EC-241): an exact tag match wins, else the base language (`de-DE` → `de`), else\n * `defaultLocale`. Pure + deterministic — the browser list is the only input.\n */\nexport function resolveActiveLocale(\n available: readonly string[],\n preferred: readonly string[],\n defaultLocale: string,\n): string {\n const lower = available.map((a) => a.toLowerCase())\n for (const pref of preferred) {\n const p = pref.toLowerCase()\n const base = p.split('-')[0] ?? p\n const at = lower.findIndex((a) => a === p || a === base)\n if (at >= 0) return available[at]!\n }\n return defaultLocale\n}\n\ninterface ResolvedI18n {\n locale: string\n defaultLocale: string\n /** The active-locale catalog (empty when active === default → the English source is used). */\n active: MessageCatalog\n source: SourceCatalog\n}\n\nlet localeOverride: string | null = null\n\ntype LanguagesResolver = () => readonly string[] | null | undefined\nlet serverLanguagesResolver: LanguagesResolver | null = null\n\n/**\n * Provide the request's preferred languages for **SSR** (EC-241). The server has no\n * `navigator`, so without this the server renders the default locale while the client\n * renders the browser locale — a hydration mismatch (server text ≠ client text). A\n * host (e.g. the TanStack Start root) sets a resolver that reads the request's\n * `Accept-Language` header. It is invoked per render, so when the host reads from\n * request-scoped storage (TanStack's AsyncLocalStorage) it stays concurrency-safe —\n * the engine keeps no request state. A no-op on the client, where `navigator` wins.\n */\nexport function setServerLanguagesResolver(fn: LanguagesResolver | null): void {\n serverLanguagesResolver = fn\n}\n\n/**\n * Parse an HTTP `Accept-Language` header into an ordered list of language tags,\n * highest q-weight first: `de,en-US;q=0.7,en;q=0.3` → `['de', 'en-US', 'en']`. The\n * server equivalent of `navigator.languages`, so SSR resolves the same locale the\n * client will.\n */\nexport function parseAcceptLanguage(header: string | null | undefined): string[] {\n if (!header) return []\n return header\n .split(',')\n .map((part) => {\n const [tag, ...params] = part.trim().split(';')\n const q = params.map((p) => p.trim()).find((p) => p.startsWith('q='))\n const weight = q ? Number.parseFloat(q.slice(2)) : 1\n return { tag: (tag ?? '').trim(), weight: Number.isFinite(weight) ? weight : 1 }\n })\n .filter((entry) => entry.tag !== '' && entry.tag !== '*')\n .sort((a, b) => b.weight - a.weight)\n .map((entry) => entry.tag)\n}\n\nfunction navigatorLanguages(): string[] {\n if (typeof navigator !== 'undefined') {\n if (navigator.languages && navigator.languages.length > 0) return [...navigator.languages]\n if (navigator.language) return [navigator.language]\n }\n // SSR (no navigator): a host may resolve the request's Accept-Language.\n const server = serverLanguagesResolver?.()\n return server ? [...server] : []\n}\n\nconst warned = new Set<string>()\nfunction warnOnce(message: string): void {\n if (warned.has(message)) return\n warned.add(message)\n if (typeof console !== 'undefined') console.warn(message)\n}\n\n/**\n * Resolve the studio i18n from the config holder + the browser locale (EC-241).\n *\n * NOT cached: the studio config holder (`createStudio`) is seeded at the mount, which\n * runs AFTER the consumer's `studio.config` module built its sidebar — so an eager\n * `translate` during that sidebar build (e.g. a built-in view label) sees an empty\n * config. Caching the first result would poison every later render-time call with\n * that empty-config English. Re-resolving each call is cheap (a few array ops) and\n * always reflects the config once the mount has run. `translate`/`localizedLabel`\n * are the hot callers; built-in view labels are lazy getters so they re-resolve too.\n */\nexport function resolveStudioI18n(): ResolvedI18n {\n const config = resolveDeploymentI18n() ?? {}\n const defaultLocale = config.defaultLocale ?? BUILTIN_DEFAULT_LOCALE\n const locales = config.locales ?? {}\n const available = [defaultLocale, ...Object.keys(locales).filter((l) => l !== defaultLocale)]\n // A config-pinned locale (EC-241) takes precedence over browser detection: it is read\n // from config — identical on server and client — so SSR and hydration agree (no\n // navigator-vs-server split). An unavailable pin is ignored with a visible signal\n // (\"failures are first-class\"), and detection resumes.\n let pinned: string | undefined\n if (config.locale !== undefined) {\n if (available.includes(config.locale)) pinned = config.locale\n else\n warnOnce(\n `[i18n] pinned locale \"${config.locale}\" is not available (default \"${defaultLocale}\" + ${JSON.stringify(Object.keys(locales))}); using browser detection.`,\n )\n }\n const locale =\n localeOverride ?? pinned ?? resolveActiveLocale(available, navigatorLanguages(), defaultLocale)\n const active = locale === defaultLocale ? {} : (locales[locale] ?? {})\n // Coverage lint: warn once when the active locale doesn't cover every English key.\n if (locale !== defaultLocale && locales[locale]) {\n const missing = Object.keys(EN_MESSAGES).filter((k) => !(k in active))\n if (missing.length > 0) {\n warnOnce(\n `[i18n] locale \"${locale}\" is missing ${missing.length} message(s); falling back to English for those.`,\n )\n }\n }\n return { locale, defaultLocale, active, source: EN_MESSAGES }\n}\n\nfunction interpolate(text: string, vars: Record<string, string | number>): string {\n return text.replace(/\\{(\\w+)\\}/g, (whole, key: string) => (key in vars ? String(vars[key]) : whole))\n}\n\n/**\n * Translate a message key for the active UI locale (EC-241): active-locale string\n * ?? English source ?? **the key itself** (a visible fallback + a one-time console\n * signal — \"failures are first-class\", never a silent blank). Non-hook — reads the\n * per-boot singleton, so config-build and pure code can localize too; {@link useT}\n * is the React-idiomatic wrapper.\n */\nexport function translate(key: string, vars?: Record<string, string | number>): string {\n const i18n = resolveStudioI18n()\n const hit = i18n.active[key] ?? i18n.source[key]?.message\n if (hit === undefined) {\n warnOnce(`[i18n] missing message key: \"${key}\"`)\n return key\n }\n return vars ? interpolate(hit, vars) : hit\n}\n\n/**\n * A **catalog-backed** schema label (EC-241): a label whose text comes from the message\n * catalog by `key`, not a hard-coded string or a per-locale map. This is how the\n * engine's own built-in schemas (the redirects/users rails) localize — their default\n * labels resolve through the *same* consumer catalog as the rest of the chrome, so one\n * German catalog covers them with no per-rail override and no per-language data in\n * engine code. Consumers never author these (their labels are plain strings or\n * `{ en, de }` maps); it is an engine-internal seam.\n *\n * Encoded as a sentinel-prefixed string so it is a valid {@link LocalizedString} (no\n * change to the serializable schema type) and survives zod parse / object spread — it\n * is decoded only at the final render site by {@link resolveMsgLabel}. On the delivery\n * side (no catalog) `resolveLabel` returns it verbatim, which is harmless: the built-in\n * rails never render there.\n */\nconst MSG_LABEL_SENTINEL = '@@msg:'\nexport function msgLabel(key: string): LocalizedString {\n return MSG_LABEL_SENTINEL + key\n}\n\n/**\n * Decode a {@link msgLabel} to its translated string for the active locale, or\n * `undefined` when the value is not a catalog-backed label (a plain string / locale\n * map / absent). Every studio label read site checks this first, then falls back to\n * {@link resolveLabel} for ordinary labels.\n */\nexport function resolveMsgLabel(value: unknown): string | undefined {\n return typeof value === 'string' && value.startsWith(MSG_LABEL_SENTINEL)\n ? translate(value.slice(MSG_LABEL_SENTINEL.length))\n : undefined\n}\n\n/**\n * Resolve a {@link LocalizedString} (field/collection/option label) against the\n * active UI locale (EC-241) — **non-hook**, reading the per-boot singleton, so it is\n * safe to call anywhere: a component body, a nested render helper, or config-build\n * code. Returns `fallback` (default `''`) when the value is absent. Prefer this over\n * `resolveLabel(x, useUiLocale())` at render sites — it localizes without a hook, so\n * it can't trip the rules-of-hooks in a conditional/nested position. A catalog-backed\n * {@link msgLabel} (the built-in rails) resolves through the message catalog.\n */\nexport function localizedLabel(value: LocalizedString | undefined, fallback = ''): string {\n const fromCatalog = resolveMsgLabel(value)\n if (fromCatalog !== undefined) return fromCatalog\n const { locale, defaultLocale } = resolveStudioI18n()\n return resolveLabel(value, locale, defaultLocale) ?? fallback\n}\n\n// --- React hooks ---\n\n/** The active studio-UI locale (browser-resolved). */\nexport function useUiLocale(): string {\n return resolveStudioI18n().locale\n}\n\n/** A `t(key, vars?)` translator bound to the active locale. */\nexport function useT(): (key: string, vars?: Record<string, string | number>) => string {\n return translate\n}\n\n/**\n * Resolve a {@link LocalizedString} label (field/collection/option) for the active\n * locale. Re-reads the locale each render (keyed into the memo) so it never captures\n * a locale resolved before the mount seeded the i18n config.\n */\nexport function useLabel(): (value: LocalizedString | undefined, fallback?: string) => string {\n const { locale, defaultLocale } = resolveStudioI18n()\n return useMemo(\n () => (value, fallback) =>\n resolveMsgLabel(value) ?? resolveLabel(value, locale, defaultLocale) ?? fallback ?? '',\n [locale, defaultLocale],\n )\n}\n\n/** Test seam: force the active locale. Never used by app code. */\nexport function setUiLocaleForTests(locale: string | null): void {\n localeOverride = locale\n warned.clear()\n}\n\n/** Test seam: reset i18n state (once-per-boot warnings + the SSR resolver). Never used by app code. */\nexport function resetStudioI18nForTests(): void {\n warned.clear()\n serverLanguagesResolver = null\n}\n"]}
@@ -9,4 +9,4 @@
9
9
  export type { SourceMessage, SourceCatalog, MessageCatalog, StudioI18nConfig } from './types';
10
10
  export { msg } from './types';
11
11
  export { EN_MESSAGES } from './messages.en';
12
- export { resolveActiveLocale, resolveStudioI18n, translate, localizedLabel, useT, useUiLocale, useLabel, parseAcceptLanguage, setServerLanguagesResolver, setUiLocaleForTests, resetStudioI18nForTests, } from './i18n';
12
+ export { resolveActiveLocale, resolveStudioI18n, translate, localizedLabel, msgLabel, resolveMsgLabel, useT, useUiLocale, useLabel, parseAcceptLanguage, setServerLanguagesResolver, setUiLocaleForTests, resetStudioI18nForTests, } from './i18n';
@@ -1,4 +1,4 @@
1
1
  export { msg } from './types';
2
2
  export { EN_MESSAGES } from './messages.en';
3
- export { resolveActiveLocale, resolveStudioI18n, translate, localizedLabel, useT, useUiLocale, useLabel, parseAcceptLanguage, setServerLanguagesResolver, setUiLocaleForTests, resetStudioI18nForTests, } from './i18n';
3
+ export { resolveActiveLocale, resolveStudioI18n, translate, localizedLabel, msgLabel, resolveMsgLabel, useT, useUiLocale, useLabel, parseAcceptLanguage, setServerLanguagesResolver, setUiLocaleForTests, resetStudioI18nForTests, } from './i18n';
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/i18n/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,QAAQ,CAAA","sourcesContent":["/**\n * `@elytracms/studio/lib/i18n` — studio-UI localization (EC-241).\n *\n * - Public config surface (`StudioI18nConfig`, `MessageCatalog`, `msg`) is re-exported\n * from `@elytracms/studio/customization` so a consumer authors catalogs there.\n * - Studio components localize chrome via `translate`/`useT` and schema labels via\n * `useLabel`.\n */\nexport type { SourceMessage, SourceCatalog, MessageCatalog, StudioI18nConfig } from './types'\nexport { msg } from './types'\nexport { EN_MESSAGES } from './messages.en'\nexport {\n resolveActiveLocale,\n resolveStudioI18n,\n translate,\n localizedLabel,\n useT,\n useUiLocale,\n useLabel,\n parseAcceptLanguage,\n setServerLanguagesResolver,\n setUiLocaleForTests,\n resetStudioI18nForTests,\n} from './i18n'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/i18n/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,QAAQ,CAAA","sourcesContent":["/**\n * `@elytracms/studio/lib/i18n` — studio-UI localization (EC-241).\n *\n * - Public config surface (`StudioI18nConfig`, `MessageCatalog`, `msg`) is re-exported\n * from `@elytracms/studio/customization` so a consumer authors catalogs there.\n * - Studio components localize chrome via `translate`/`useT` and schema labels via\n * `useLabel`.\n */\nexport type { SourceMessage, SourceCatalog, MessageCatalog, StudioI18nConfig } from './types'\nexport { msg } from './types'\nexport { EN_MESSAGES } from './messages.en'\nexport {\n resolveActiveLocale,\n resolveStudioI18n,\n translate,\n localizedLabel,\n msgLabel,\n resolveMsgLabel,\n useT,\n useUiLocale,\n useLabel,\n parseAcceptLanguage,\n setServerLanguagesResolver,\n setUiLocaleForTests,\n resetStudioI18nForTests,\n} from './i18n'\n"]}
@@ -460,11 +460,25 @@ export const EN_MESSAGES = {
460
460
  'users.restrictedBody': msg('Managing users and roles requires the admin role on this deployment. Ask an admin to grant you access.'),
461
461
  'users.loadFailed': msg('Users failed to load'),
462
462
  'users.loading': msg('Loading users…'),
463
+ // Built-in users rail — its schema labels resolve through the catalog (msgLabel),
464
+ // so a consumer's translation catalog localizes the rail with no per-rail override.
465
+ 'users.rail.label': msg('Users'),
466
+ 'users.rail.labelSingular': msg('user', 'Singular noun for one users-rail row, e.g. in a header.'),
467
+ 'users.field.name.label': msg('Name'),
468
+ 'users.field.email.label': msg('Email'),
469
+ 'users.field.role.label': msg('Role'),
463
470
  // ─────────────────────────────────────────────────────────────────────────
464
471
  // Redirects (section)
465
472
  // ─────────────────────────────────────────────────────────────────────────
466
473
  'redirects.loadFailed': msg('Redirects failed to load'),
467
474
  'redirects.loading': msg('Loading redirects…'),
475
+ // Built-in redirects rail — schema labels via the catalog (msgLabel), see above.
476
+ 'redirects.rail.label': msg('Redirects'),
477
+ 'redirects.rail.labelSingular': msg('redirect', 'Singular noun for one redirect row, e.g. in a header.'),
478
+ 'redirects.field.from.label': msg('From'),
479
+ 'redirects.field.to.label': msg('To'),
480
+ 'redirects.field.permanent.label': msg('Permanent (301)'),
481
+ 'redirects.field.enabled.label': msg('Enabled'),
468
482
  // ─────────────────────────────────────────────────────────────────────────
469
483
  // References panel
470
484
  // ─────────────────────────────────────────────────────────────────────────