@yahoo/uds-create-config 5.91.8 → 5.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { GraftableElement, GraftableSpec, PreviewElement, PreviewRef, PreviewSpecNode, PreviewValue, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, previewElementNodes, previewElementType } from "./preview-elements.js";
1
+ import { GraftableElement, GraftableSpec, PreviewElement, PreviewRef, PreviewSpecNode, PreviewValue, graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, previewElementNodes, previewElementType } from "./preview-elements.js";
2
2
  import { Slot, SlotCell } from "./slot.js";
3
3
  import { Cell, CellSlot } from "./cell.js";
4
4
  import { DocumentRename, RewritableElement, RewritableSpec, SpecRewrite, componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, rewriteSpecRefs, styleNumberReadingRenames } from "./rewrite-refs.js";
@@ -29,4 +29,4 @@ import { SpecToJsxOptions, SpecToJsxResult, specToJsx } from "./specToJsx.js";
29
29
  * element, without changing the rendered layer hierarchy. */
30
30
  declare const SYNTHETIC_TEXT_SLOT_PROP = "data-uds-synthetic-text-slot";
31
31
  //#endregion
32
- export { type AcceptsChildNodes, type Cell, type CellSlot, type ChildNodesClassification, type ClassifyChildNodes, type CollapseTextLabelsResult, type CollapsedTextLabel, type DocumentRename, type GlyphJsxForm, type GlyphNodeResolver, type GraftableElement, type GraftableSpec, type JsxToSpecOptions, type MappedInstance, type MappedProps, type MappingScope, type MatchedValue, type PreviewElement, type PreviewRef, type PreviewSpecNode, type PreviewValue, type PropMapping, type PropMappingConflict, type PropMappingResult, type PropMappingRule, type RewritableElement, type RewritableSpec, SYNTHETIC_TEXT_SLOT_PROP, type Slot, type SlotCell, type SpecRewrite, type SpecToJsxOptions, type SpecToJsxResult, UNRESOLVED, applyForcedModifiers, applyPropMapping, buildAcceptsChildNodes, buildClassifyChildNodes, collapseWrappedTextLabels, collectForcedModifierProps, componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, glyphJsxForm, glyphMemberOf, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, hasUnresolvedProps, isComponentRef, isPreviewElement, isPreviewRef, jsxIdentifier, jsxToSpec, mapComponentProps, mapPropsRulesSchema, mappingFromSchema, mappingScopeSchema, onlyMapsProps, parseGlyphType, previewElementNodes, previewElementType, propMappingErrors, propMappingRuleSchema, propMappingRulesSchema, propMappingsIn, rewriteSpecRefs, specToJsx, stripInjectedSlots, stripUnresolvedProps, styleNumberReadingRenames, swapMappingRulesSchema, withContainerChildSlots, withEmptyNodeSlots, withRenderSlots };
32
+ export { type AcceptsChildNodes, type Cell, type CellSlot, type ChildNodesClassification, type ClassifyChildNodes, type CollapseTextLabelsResult, type CollapsedTextLabel, type DocumentRename, type GlyphJsxForm, type GlyphNodeResolver, type GraftableElement, type GraftableSpec, type JsxToSpecOptions, type MappedInstance, type MappedProps, type MappingScope, type MatchedValue, type PreviewElement, type PreviewRef, type PreviewSpecNode, type PreviewValue, type PropMapping, type PropMappingConflict, type PropMappingResult, type PropMappingRule, type RewritableElement, type RewritableSpec, SYNTHETIC_TEXT_SLOT_PROP, type Slot, type SlotCell, type SpecRewrite, type SpecToJsxOptions, type SpecToJsxResult, UNRESOLVED, applyForcedModifiers, applyPropMapping, buildAcceptsChildNodes, buildClassifyChildNodes, collapseWrappedTextLabels, collectForcedModifierProps, componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, glyphJsxForm, glyphMemberOf, graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, hasUnresolvedProps, isComponentRef, isPreviewElement, isPreviewRef, jsxIdentifier, jsxToSpec, mapComponentProps, mapPropsRulesSchema, mappingFromSchema, mappingScopeSchema, onlyMapsProps, parseGlyphType, previewElementNodes, previewElementType, propMappingErrors, propMappingRuleSchema, propMappingRulesSchema, propMappingsIn, rewriteSpecRefs, specToJsx, stripInjectedSlots, stripUnresolvedProps, styleNumberReadingRenames, swapMappingRulesSchema, withContainerChildSlots, withEmptyNodeSlots, withRenderSlots };
@@ -1,4 +1,4 @@
1
- import { graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, previewElementNodes, previewElementType } from "./preview-elements.js";
1
+ import { graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, previewElementNodes, previewElementType } from "./preview-elements.js";
2
2
  import { componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, rewriteSpecRefs, styleNumberReadingRenames } from "./rewrite-refs.js";
3
3
  import { applyPropMapping, mapComponentProps, mapPropsRulesSchema, mappingFromSchema, mappingScopeSchema, onlyMapsProps, propMappingErrors, propMappingRuleSchema, propMappingRulesSchema, propMappingsIn, swapMappingRulesSchema } from "./prop-mapping.js";
4
4
  import { glyphJsxForm, glyphMemberOf, jsxIdentifier, parseGlyphType } from "./glyph-jsx.js";
@@ -26,4 +26,4 @@ import { specToJsx } from "./specToJsx.js";
26
26
  * element, without changing the rendered layer hierarchy. */
27
27
  const SYNTHETIC_TEXT_SLOT_PROP = "data-uds-synthetic-text-slot";
28
28
  //#endregion
29
- export { SYNTHETIC_TEXT_SLOT_PROP, UNRESOLVED, applyForcedModifiers, applyPropMapping, buildAcceptsChildNodes, buildClassifyChildNodes, collapseWrappedTextLabels, collectForcedModifierProps, componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, glyphJsxForm, glyphMemberOf, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, hasUnresolvedProps, isComponentRef, isPreviewElement, isPreviewRef, jsxIdentifier, jsxToSpec, mapComponentProps, mapPropsRulesSchema, mappingFromSchema, mappingScopeSchema, onlyMapsProps, parseGlyphType, previewElementNodes, previewElementType, propMappingErrors, propMappingRuleSchema, propMappingRulesSchema, propMappingsIn, rewriteSpecRefs, specToJsx, stripInjectedSlots, stripUnresolvedProps, styleNumberReadingRenames, swapMappingRulesSchema, withContainerChildSlots, withEmptyNodeSlots, withRenderSlots };
29
+ export { SYNTHETIC_TEXT_SLOT_PROP, UNRESOLVED, applyForcedModifiers, applyPropMapping, buildAcceptsChildNodes, buildClassifyChildNodes, collapseWrappedTextLabels, collectForcedModifierProps, componentPathAfter, composeRenames, documentRenamesFromPatches, documentRenamesFromSource, glyphJsxForm, glyphMemberOf, graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, hasUnresolvedProps, isComponentRef, isPreviewElement, isPreviewRef, jsxIdentifier, jsxToSpec, mapComponentProps, mapPropsRulesSchema, mappingFromSchema, mappingScopeSchema, onlyMapsProps, parseGlyphType, previewElementNodes, previewElementType, propMappingErrors, propMappingRuleSchema, propMappingRulesSchema, propMappingsIn, rewriteSpecRefs, specToJsx, stripInjectedSlots, stripUnresolvedProps, styleNumberReadingRenames, swapMappingRulesSchema, withContainerChildSlots, withEmptyNodeSlots, withRenderSlots };
@@ -72,6 +72,11 @@ type GraftableElement = {
72
72
  children?: string[];
73
73
  slots?: Record<string, string[]>;
74
74
  };
75
+ /** The attribute on each element of a copy a separator makes between items, naming the key of the
76
+ * element it copies, so a surface that selects the copy selects the original. Inert in the DOM. */
77
+ declare const COPY_OF_ATTR = "data-uds-copy-of";
78
+ /** The key prefix of the elements a graft makes for one slot prop under one host. */
79
+ declare function graftPrefix(hostKey: string, prop: string): string;
75
80
  /**
76
81
  * Graft a slot's content under its host: the elements join the spec's keyed element map as
77
82
  * `<host>__<prop>__<index>` subtrees, and the host's `slots[into]` names their roots — json-render
@@ -80,6 +85,10 @@ type GraftableElement = {
80
85
  * pass holds and nothing stale is left for the next key to collide with. The spec comes back
81
86
  * unchanged, by reference, when the grafted content is already what is there.
82
87
  *
88
+ * With `separator`, the slot is the items of a render's `intersperse(children, separator)`: the
89
+ * separator's content is grafted under its own prop's keys into the first gap between the items, and
90
+ * each later gap holds a copy keyed `<key>#<gap>`, every element of it marked {@link COPY_OF_ATTR}.
91
+ *
83
92
  * Every host that grafts slot content goes through here: the tile projection, the matrix cell and
84
93
  * the cell panel, so their keys agree and the layers rail and the drop hit-test read one scheme.
85
94
  */
@@ -88,13 +97,18 @@ declare function graftSlotContent<S extends GraftableSpec>({
88
97
  hostKey,
89
98
  prop,
90
99
  into,
91
- elements: content
100
+ elements: content,
101
+ separator
92
102
  }: {
93
103
  spec: S; /** The element whose `slots` names the fills. */
94
104
  hostKey: string; /** The slot prop the content arrives as, which the grafted keys carry. */
95
105
  prop: string; /** The host element's prop the fills land under. */
96
106
  into: string;
97
- elements: readonly PreviewElement[];
107
+ elements: readonly PreviewElement[]; /** The slot whose content goes between the items, and what it holds. */
108
+ separator?: {
109
+ prop: string;
110
+ elements: readonly PreviewElement[];
111
+ };
98
112
  }): S;
99
113
  /**
100
114
  * Lower the root's direct element-valued props into json-render's native slot form, one
@@ -107,4 +121,4 @@ declare function graftSlotContent<S extends GraftableSpec>({
107
121
  */
108
122
  declare function graftPreviewElements<S extends GraftableSpec>(spec: S, values: Record<string, unknown>): S;
109
123
  //#endregion
110
- export { GraftableElement, GraftableSpec, PreviewElement, PreviewRef, PreviewSpecNode, PreviewStatePins, PreviewValue, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, isPreviewStatePins, previewElementNodes, previewElementType };
124
+ export { COPY_OF_ATTR, GraftableElement, GraftableSpec, PreviewElement, PreviewRef, PreviewSpecNode, PreviewStatePins, PreviewValue, graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, isPreviewStatePins, previewElementNodes, previewElementType };
@@ -86,6 +86,13 @@ function previewElementNodes(root, rootKey, taken = /* @__PURE__ */ new Set()) {
86
86
  function isElementValue(value) {
87
87
  return isPreviewElement(value) || Array.isArray(value) && value.some(isPreviewElement);
88
88
  }
89
+ /** The attribute on each element of a copy a separator makes between items, naming the key of the
90
+ * element it copies, so a surface that selects the copy selects the original. Inert in the DOM. */
91
+ const COPY_OF_ATTR = "data-uds-copy-of";
92
+ /** The key prefix of the elements a graft makes for one slot prop under one host. */
93
+ function graftPrefix(hostKey, prop) {
94
+ return `${hostKey}__${prop}__`;
95
+ }
89
96
  /**
90
97
  * Graft a slot's content under its host: the elements join the spec's keyed element map as
91
98
  * `<host>__<prop>__<index>` subtrees, and the host's `slots[into]` names their roots — json-render
@@ -94,25 +101,56 @@ function isElementValue(value) {
94
101
  * pass holds and nothing stale is left for the next key to collide with. The spec comes back
95
102
  * unchanged, by reference, when the grafted content is already what is there.
96
103
  *
104
+ * With `separator`, the slot is the items of a render's `intersperse(children, separator)`: the
105
+ * separator's content is grafted under its own prop's keys into the first gap between the items, and
106
+ * each later gap holds a copy keyed `<key>#<gap>`, every element of it marked {@link COPY_OF_ATTR}.
107
+ *
97
108
  * Every host that grafts slot content goes through here: the tile projection, the matrix cell and
98
109
  * the cell panel, so their keys agree and the layers rail and the drop hit-test read one scheme.
99
110
  */
100
- function graftSlotContent({ spec, hostKey, prop, into, elements: content }) {
111
+ function graftSlotContent({ spec, hostKey, prop, into, elements: content, separator }) {
101
112
  const host = spec.elements[hostKey];
102
113
  if (!host) return spec;
103
- const prefix = `${hostKey}__${prop}__`;
104
- const isGrafted = (key) => key.startsWith(prefix) && /^\d/.test(key.slice(prefix.length));
114
+ const prefix = graftPrefix(hostKey, prop);
115
+ const separatorPrefix = separator ? graftPrefix(hostKey, separator.prop) : void 0;
116
+ const under = (key, of) => of !== void 0 && key.startsWith(of) && /^\d/.test(key.slice(of.length));
117
+ const isGrafted = (key) => under(key, prefix) || under(key, separatorPrefix);
105
118
  const kept = Object.fromEntries(Object.entries(spec.elements).filter(([key]) => !isGrafted(key)));
106
119
  const grafted = {};
107
120
  const used = new Set(Object.keys(kept));
108
- const roots = content.map((node, index) => {
109
- const built = previewElementNodes(node, `${prefix}${index}`, used);
121
+ const build = (node, base) => {
122
+ const built = previewElementNodes(node, base, used);
110
123
  for (const [key, element] of Object.entries(built.elements)) {
111
124
  grafted[key] = element;
112
125
  used.add(key);
113
126
  }
114
- return built.root;
115
- });
127
+ return built;
128
+ };
129
+ const items = content.map((node, index) => build(node, `${prefix}${index}`).root);
130
+ let roots = items;
131
+ if (separator && separatorPrefix && items.length > 1) {
132
+ const originals = separator.elements.map((node, index) => build(node, `${separatorPrefix}${index}`));
133
+ roots = items.flatMap((item, gap) => {
134
+ if (gap === 0) return [item];
135
+ if (gap === 1) return [...originals.map((built) => built.root), item];
136
+ return [...separator.elements.map((node, index) => {
137
+ const copy = build(node, `${separatorPrefix}${index}#${gap}`);
138
+ const from = Object.keys(originals[index]?.elements ?? {});
139
+ Object.keys(copy.elements).forEach((key, at) => {
140
+ const element = grafted[key];
141
+ if (!element) return;
142
+ grafted[key] = {
143
+ ...element,
144
+ props: {
145
+ ...element.props,
146
+ [COPY_OF_ATTR]: from[at]
147
+ }
148
+ };
149
+ });
150
+ return copy.root;
151
+ }), item];
152
+ });
153
+ }
116
154
  const current = host.slots?.[into];
117
155
  if (current !== void 0 && current.length === roots.length && roots.every((root, index) => current[index] === root) && Object.keys(spec.elements).filter(isGrafted).length === Object.keys(grafted).length && Object.entries(grafted).every(([key, element]) => JSON.stringify(spec.elements[key]) === JSON.stringify(element))) return spec;
118
156
  return {
@@ -172,4 +210,4 @@ function graftPreviewElements(spec, values) {
172
210
  return next;
173
211
  }
174
212
  //#endregion
175
- export { graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, isPreviewStatePins, previewElementNodes, previewElementType };
213
+ export { COPY_OF_ATTR, graftPrefix, graftPreviewElements, graftSlotContent, hasPreviewElementDeep, isComponentRef, isPreviewElement, isPreviewRef, isPreviewStatePins, previewElementNodes, previewElementType };