@pairdraw/dom-css 0.19.0 → 0.19.2
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.
- package/dist/browser.d.ts +16 -1
- package/dist/browser.js +2 -2
- package/dist/chunks/behaviours/controls.js +34 -2
- package/dist/chunks/behaviours/controls.js.map +1 -1
- package/dist/chunks/behaviours/states/layers.js +25 -0
- package/dist/chunks/behaviours/states/layers.js.map +1 -1
- package/dist/chunks/behaviours/states/tailwind.js +17 -2
- package/dist/chunks/behaviours/states/tailwind.js.map +1 -1
- package/dist/chunks/browser.js +228 -49
- package/dist/chunks/browser.js.map +1 -1
- package/dist/chunks/export/components/groups.js +3 -2
- package/dist/chunks/export/components/groups.js.map +1 -1
- package/dist/chunks/export/components/layers.js +50 -8
- package/dist/chunks/export/components/layers.js.map +1 -1
- package/dist/export.d.ts +9 -0
- package/dist/scene-graph2.d.ts +6 -0
- package/package.json +3 -3
- package/src/behaviours/controls.ts +49 -2
- package/src/behaviours/states/tailwind.ts +4 -1
- package/src/browser.ts +1 -0
- package/src/export/components/model.ts +60 -7
- package/src/export/components/react/index.ts +4 -0
- package/src/export/components/repeats.ts +7 -2
- package/src/export/components/vue.ts +38 -9
- package/src/export/font-size-class.ts +13 -0
- package/src/export/html.ts +5 -1
- package/src/export/projection.ts +26 -0
- package/src/import/flow.ts +15 -0
- package/src/import/fonts.ts +59 -0
- package/src/import/scene-graph.ts +190 -47
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groups.js","names":[],"sources":["../../../../src/export/components/references.ts","../../../../src/export/components/repeats.ts","../../../../src/export/components/groups.ts"],"sourcesContent":["import { layerKind } from '#dom-css/behaviours/states/layers'\nimport type { StateElement } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { isIconModified, isNamedIcon, readIcon } from '@pairdraw/scene-graph/icons'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport { drawsAsMain } from './drawn'\nimport type { ComponentModel } from './model'\n\n/** A prop a reference sets on the component it uses: a variant or text value, or `disabled`. */\ninterface ReferenceProp {\n name: string\n value: string | boolean\n}\n\n/**\n * Another generated component used where the design places an instance of it, with the values\n * the instance shows. Its own layers are the component's, so they are not drawn here.\n */\nexport interface ComponentReference {\n type: 'reference'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** The component's identifier and file name. */\n component: string\n /** The class the parent's state styles place it by. */\n className: string\n props: ReferenceProp[]\n /** The two-way value the instance is drawn with, when it is on. */\n model: string | null\n}\n\n/** An icon from a set, drawn by the framework's Iconify component. */\nexport interface IconReference {\n type: 'icon'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** `prefix:name`. */\n icon: string\n className: string\n}\n\n/**\n * How a parent places a layer, as opposed to how the layer looks. A component used in place of\n * a layer keeps its own look and state styles; the parent only places it.\n */\nconst PLACEMENT =\n /^(position|inset|left|top|right|bottom|(min-|max-)?(width|height)|margin(-.+)?|flex(-(grow|shrink|basis))?|align-self|justify-self|order|grid-(area|column|row)(-.+)?|transform(-origin)?|rotate|translate|scale|z-index)$/\n\n/** Whether a declaration places a layer rather than drawing it. */\nexport const isPlacement = (property: string) => PLACEMENT.test(property)\n\n/** Whether a declaration hides or shows a layer by state, which the parent decides too. */\nconst isVisibility = (property: string, value: string) =>\n property === 'display' && (value === 'none' || value === 'revert')\n\n/** Keeps only where the parent places a layer, and whether a state shows it. */\nexport function placementOnly(element: StateElement): void {\n const placement = (style: DesignStyleDeclaration): DesignStyleDeclaration =>\n Object.fromEntries(\n Object.entries(style).filter(\n ([property, value]) => isPlacement(property) || isVisibility(property, value)\n )\n )\n element.base = placement(element.base)\n element.rules = element.rules\n .map((rule) => ({ ...rule, style: placement(rule.style) }))\n .filter((rule) => !isEmptyObject(rule.style))\n}\n\n/** Generated components by the id of the set they come from, which instances refer to. */\nexport type ComponentReferences = ReadonlyMap<string, ComponentModel>\n\n/** The set a component belongs to, or the component itself when it stands alone. */\nfunction ownerId(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.id : component.id\n}\n\n/**\n * The words an instance shows for a text property: an assignment that overrides the default,\n * else what its bound text layer reads, which a direct edit changes, else the assignment.\n */\nexport function shownText(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): string | undefined {\n const assigned = instance.componentPropertyAssignments[propertyId]\n const main = instanceMainComponent(graph, instance)\n const owner = main && behaviourOwner(graph, main)\n const definition = owner?.componentPropertyDefinitions.find((item) => item.id === propertyId)\n if (typeof assigned === 'string' && assigned !== definition?.defaultValue) return assigned\n const target = findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.field === 'TEXT' && item.node.type === 'TEXT'\n )\n return target?.node.text ?? (typeof assigned === 'string' ? assigned : undefined)\n}\n\n/**\n * What `instance` sets on `component`: the values it is drawn with that differ from defaults,\n * and whether it is drawn on: its model, or for a group's item the value that marks it chosen.\n */\nexport function referenceValues(\n graph: SceneGraph,\n instance: SceneNode,\n component: ComponentModel\n): Pick<ComponentReference, 'props' | 'model'> {\n const values = instanceMainComponent(graph, instance)?.componentPropertyValues ?? {}\n const props: ReferenceProp[] = []\n let model: string | null = null\n for (const [property, arg] of component.args.booleans) {\n if (values[property] !== arg.on) continue\n const on = arg.name === component.model || (component.valueProp && arg.name !== 'disabled')\n if (on) model = arg.name\n else props.push({ name: arg.name, value: true })\n }\n const states = component.args.states\n if (states?.disabled && values[states.property] === states.disabled)\n props.push({ name: 'disabled', value: true })\n for (const prop of component.props) {\n const value = values[prop.property]\n if (Object.hasOwn(values, prop.property) && value !== prop.default)\n props.push({ name: prop.name, value })\n }\n for (const text of component.texts) {\n const value = shownText(graph, instance, text.id)\n if (value !== undefined && value !== text.default) props.push({ name: text.name, value })\n }\n for (const prop of component.booleans) {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, prop.id)\n ? assignments[prop.id] === 'true'\n : prop.default\n if (value !== prop.default) props.push({ name: prop.name, value })\n }\n return { props, model }\n}\n\n/** A used layer, before the parent's class name for it is known. */\nexport type UsedLayer = Omit<ComponentReference, 'className'> | Omit<IconReference, 'className'>\n\n/**\n * What the layer at `element` uses in place of drawing itself, if anything, read from the first\n * variant that draws it as that element: the rest state, or the one that shows it, such as open\n * content.\n */\nfunction usedLayer(\n graph: SceneGraph,\n variantIds: readonly string[],\n element: StateElement,\n references: ComponentReferences\n): UsedLayer | null {\n const path = element.key.split('\\0')[0] ?? ''\n // The variant's layer at that path drawn as this element is: a frame, or that instance or icon.\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found !== undefined && layerKind(graph, found) === element.kind)\n if (!node) return null\n const main = node.type === 'INSTANCE' ? instanceMainComponent(graph, node) : undefined\n // An instance changed beyond its properties draws its own layers, which the component's\n // props could not reproduce.\n const component =\n main && drawsAsMain(graph, node, main) ? references.get(ownerId(graph, main)) : undefined\n if (component)\n return {\n type: 'reference',\n component: component.name,\n ...referenceValues(graph, node, component)\n }\n const icon = readIcon(node)\n return icon && isNamedIcon(icon) && !isIconModified(graph, node)\n ? { type: 'icon', icon: icon.name }\n : null\n}\n\n/**\n * The layers of a set's merged markup that are used rather than drawn: instances of other\n * generated components, and icons from a set, read from the variants in order, the rest state\n * first. Their own layers are dropped from the markup and the styles, which belong to the\n * component or the icon.\n */\nexport function referencedLayers(\n graph: SceneGraph,\n root: StateElement,\n variantIds: readonly string[],\n references: ComponentReferences,\n /** Layers already used otherwise, such as a group's items. */\n taken: ReadonlyMap<StateElement, unknown> = new Map()\n): Map<StateElement, UsedLayer> {\n const used = new Map<StateElement, UsedLayer>()\n const visit = (element: StateElement) => {\n for (const child of element.children) {\n if (child.type !== 'element' || taken.has(child)) continue\n const layer = usedLayer(graph, variantIds, child, references)\n if (!layer) {\n visit(child)\n continue\n }\n used.set(child, layer)\n child.children = []\n if (layer.type === 'reference') placementOnly(child)\n }\n }\n visit(root)\n return used\n}\n","import { difference } from '#dom-css/behaviours/states/model'\nimport type { StateElement, StateNode } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\nimport { kebabCase } from 'es-toolkit/string'\n\nimport { claimName } from '../storybook/names'\nimport { isPlacement } from './references'\n\n/** A layer drawn once per value, such as a tab's trigger or its panel, and the value it is. */\nexport interface RepeatedPart {\n part: string\n value: string\n}\n\n/**\n * The string a component chooses among, such as the open tab, and the one it starts on, or\n * none, as a radio group with no item chosen.\n */\nexport interface ChoiceModel {\n options: string[]\n default: string | null\n}\n\n/** The words a layer reads, joined across its text. */\nexport function textOf(node: StateNode): string {\n if (node.type === 'text') return node.text\n return node.children.map(textOf).join(' ')\n}\n\nconst elementsOf = (element: StateElement | undefined) =>\n (element?.children ?? []).filter((child): child is StateElement => child.type === 'element')\n\n/**\n * The value each label stands for: the label as a slug, such as `account`, apart from the\n * others, or its position when it has no words.\n */\nexport function slugValues(labels: readonly string[]): string[] {\n const taken = new Set<string>()\n return labels.map((label, index) => claimName(kebabCase(label) || String(index), taken))\n}\n\n/**\n * Tabs' triggers, the layers in its list, and its panels, the layers in its panels slot, each\n * with the value of the tab it belongs to, matched by position. The tabs start on the first.\n */\nexport function tabParts(parts: ReadonlyMap<StateElement, string>): {\n repeated: Map<StateElement, RepeatedPart>\n choice: ChoiceModel | null\n} {\n const partElement = (id: string) => [...parts].find(([, part]) => part === id)?.[0]\n const triggers = elementsOf(partElement('list'))\n const values = slugValues(triggers.map(textOf))\n const repeated = new Map<StateElement, RepeatedPart>()\n for (const [index, trigger] of triggers.entries())\n repeated.set(trigger, { part: 'trigger', value: values[index] ?? String(index) })\n for (const [index, panel] of elementsOf(partElement('panels')).entries()) {\n const value = values.at(index)\n if (value !== undefined) repeated.set(panel, { part: 'content', value })\n }\n const first = values.at(0)\n return { repeated, choice: first === undefined ? null : { options: values, default: first } }\n}\n\n/** How `drawn` looks different from `base`, leaving out where each is placed. */\nfunction lookChange(\n base: DesignStyleDeclaration,\n drawn: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const changed = Object.entries(difference(base, drawn))\n return Object.fromEntries(changed.filter(([property]) => !isPlacement(property)))\n}\n\n/** `base` with `change` applied, where `unset` drops a declaration. */\nfunction applied(\n base: DesignStyleDeclaration,\n change: DesignStyleDeclaration\n): DesignStyleDeclaration {\n return Object.fromEntries([\n ...Object.entries(base).filter(([property]) => change[property] !== 'unset'),\n ...Object.entries(change).filter(([, value]) => value !== 'unset')\n ])\n}\n\n/** The layer of `into` where `from` has `child`: the same name, and the same one of that name. */\nfunction counterpart(\n child: StateElement,\n from: StateElement,\n into: StateElement\n): StateElement | undefined {\n const named = (element: StateElement) =>\n elementsOf(element).filter((item) => item.name === child.name)\n return named(into).at(named(from).indexOf(child))\n}\n\n/**\n * Tabs draw the first trigger chosen and the others not. Every trigger rests with the look of\n * the others and takes the first one's, layer by layer, while Reka or Radix marks it active;\n * each keeps its own place. A layer is matched across triggers by name, and one without a\n * counterpart keeps its own styles.\n */\nexport function activeTriggers(repeated: ReadonlyMap<StateElement, RepeatedPart>): void {\n const triggers = [...repeated].filter(([, item]) => item.part === 'trigger').map(([el]) => el)\n const first = triggers.at(0)\n const second = triggers.at(1)\n if (!first || !second) return\n // The two looks as drawn, before the first trigger rests with the others' look.\n const [active, inactive] = structuredClone([first, second])\n for (const trigger of triggers) {\n const visit = (layer: StateElement, drawn: StateElement, other: StateElement) => {\n if (trigger === first) layer.base = applied(layer.base, lookChange(drawn.base, other.base))\n // From the layer's own rest, so a trigger drawn apart still takes the chosen look.\n const look = lookChange(layer.base, drawn.base)\n if (!isEmptyObject(look))\n layer.rules.push({\n conditions: [{ type: 'state', value: 'active' }],\n on: trigger,\n style: look\n })\n for (const child of elementsOf(layer)) {\n const drawnChild = counterpart(child, layer, drawn)\n const otherChild = counterpart(child, layer, other)\n if (drawnChild && otherChild) visit(child, drawnChild, otherChild)\n }\n }\n visit(trigger, active, inactive)\n }\n}\n","import type { StateElement } from '#dom-css/behaviours/states/types'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport type { ComponentModel } from './model'\nimport { placementOnly, referenceValues, shownText, type UsedLayer } from './references'\nimport { slugValues, textOf, type ChoiceModel } from './repeats'\n\n/** Groups whose items are their own primitive inside the group, as Reka and Radix have them. */\nexport const GROUP_ITEMS = {\n radioGroup: 'radioGroupItem',\n toggleGroup: 'toggleGroupItem',\n accordion: 'accordionItem'\n} as const\n\nexport type GroupKind = keyof typeof GROUP_ITEMS\nexport type ItemKind = (typeof GROUP_ITEMS)[GroupKind]\n\nexport const isGroup = (kind: string): kind is GroupKind => Object.hasOwn(GROUP_ITEMS, kind)\n\n/** Builds the component of a group's items, named for the group. */\nexport type ItemBuilder = (owner: SceneNode) => ComponentModel | null\n\n/**\n * A group's items: the component they share, generated as the group's item primitive, and\n * each item in the items slot as a use of it with the value it stands for. The group chooses\n * among those values, starting on the item the design draws on, or none.\n */\nexport function groupItems(\n graph: SceneGraph,\n variantIds: readonly string[],\n itemsElement: StateElement | undefined,\n build: ItemBuilder\n): { item: ComponentModel; used: Map<StateElement, UsedLayer>; choice: ChoiceModel } | null {\n const elements = (itemsElement?.children ?? []).filter(\n (child): child is StateElement => child.type === 'element'\n )\n const instances = elements.map((element) => {\n const path = element.key.split('\\0')[0] ?? ''\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found?.type === 'INSTANCE')\n const main = node && instanceMainComponent(graph, node)\n return node && main ? { node, owner: behaviourOwner(graph, main) } : null\n })\n const owner = instances.find((instance) => instance?.owner)?.owner\n const item = owner && build(owner)\n if (!owner || !item) return null\n\n // An item is named by its label property when it has one, else by the words it reads.\n const label = item.texts.at(0)\n const values = slugValues(\n elements.map((element, index) => {\n const node = instances[index]?.node\n return (label && node && shownText(graph, node, label.id)) || textOf(element)\n })\n )\n const used = new Map<StateElement, UsedLayer>()\n let chosen: string | null = null\n for (const [index, element] of elements.entries()) {\n const instance = instances[index]\n const value = values.at(index)\n if (instance?.owner?.id !== owner.id || value === undefined) continue\n const { props, model } = referenceValues(graph, instance.node, item)\n if (model) chosen ??= value\n used.set(element, {\n type: 'reference',\n component: item.name,\n props: [{ name: 'value', value }, ...props],\n model: null\n })\n element.children = []\n placementOnly(element)\n }\n return { item, used, choice: { options: values, default: chosen } }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmDA,MAAM,YACJ;;AAGF,MAAa,eAAe,aAAqB,UAAU,KAAK,QAAQ;;AAGxE,MAAM,gBAAgB,UAAkB,UACtC,aAAa,cAAc,UAAU,UAAU,UAAU;;AAG3D,SAAgB,cAAc,SAA6B;CACzD,MAAM,aAAa,UACjB,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,CAAC,UAAU,WAAW,YAAY,QAAQ,KAAK,aAAa,UAAU,KAAK,CAC9E,CACF;CACF,QAAQ,OAAO,UAAU,QAAQ,IAAI;CACrC,QAAQ,QAAQ,QAAQ,MACrB,KAAK,UAAU;EAAE,GAAG;EAAM,OAAO,UAAU,KAAK,KAAK;CAAE,EAAE,CAAC,CAC1D,QAAQ,SAAS,CAAC,cAAc,KAAK,KAAK,CAAC;AAChD;;AAMA,SAAS,QAAQ,OAAmB,WAA8B;CAChE,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,QAAQ,SAAS,kBAAkB,OAAO,KAAK,UAAU;AAClE;;;;;AAMA,SAAgB,UACd,OACA,UACA,YACoB;CACpB,MAAM,WAAW,SAAS,6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K,SAAS,UAAU;EAC/B,MAAM,OAAO,UAAU,MAAM,EAAE;EAC/B,OAAQ,SAAS,QAAQ,UAAU,OAAO,MAAM,MAAM,EAAE,KAAM,OAAO,OAAO;CAC9E,CAAC,CACH;CACA,MAAM,uBAAO,IAAI,IAA6B;CAC9C,IAAI,SAAwB;CAC5B,KAAK,MAAM,CAAC,OAAO,YAAY,SAAS,QAAQ,GAAG;EACjD,MAAM,WAAW,UAAU;EAC3B,MAAM,QAAQ,OAAO,GAAG,KAAK;EAC7B,IAAI,UAAU,OAAO,OAAO,MAAM,MAAM,UAAU,KAAA,GAAW;EAC7D,MAAM,EAAE,OAAO,UAAU,gBAAgB,OAAO,SAAS,MAAM,IAAI;EACnE,IAAI,OAAO,WAAW;EACtB,KAAK,IAAI,SAAS;GAChB,MAAM;GACN,WAAW,KAAK;GAChB,OAAO,CAAC;IAAE,MAAM;IAAS;GAAM,GAAG,GAAG,KAAK;GAC1C,OAAO;EACT,CAAC;EACD,QAAQ,WAAW,CAAC;EACpB,cAAc,OAAO;CACvB;CACA,OAAO;EAAE;EAAM;EAAM,QAAQ;GAAE,SAAS;GAAQ,SAAS;EAAO;CAAE;AACpE"}
|
|
1
|
+
{"version":3,"file":"groups.js","names":[],"sources":["../../../../src/export/components/references.ts","../../../../src/export/components/repeats.ts","../../../../src/export/components/groups.ts"],"sourcesContent":["import { layerKind } from '#dom-css/behaviours/states/layers'\nimport type { StateElement } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { isIconModified, isNamedIcon, readIcon } from '@pairdraw/scene-graph/icons'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport { drawsAsMain } from './drawn'\nimport type { ComponentModel } from './model'\n\n/** A prop a reference sets on the component it uses: a variant or text value, or `disabled`. */\ninterface ReferenceProp {\n name: string\n value: string | boolean\n}\n\n/**\n * Another generated component used where the design places an instance of it, with the values\n * the instance shows. Its own layers are the component's, so they are not drawn here.\n */\nexport interface ComponentReference {\n type: 'reference'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** The component's identifier and file name. */\n component: string\n /** The class the parent's state styles place it by. */\n className: string\n props: ReferenceProp[]\n /** The two-way value the instance is drawn with, when it is on. */\n model: string | null\n}\n\n/** An icon from a set, drawn by the framework's Iconify component. */\nexport interface IconReference {\n type: 'icon'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** `prefix:name`. */\n icon: string\n className: string\n}\n\n/**\n * How a parent places a layer, as opposed to how the layer looks. A component used in place of\n * a layer keeps its own look and state styles; the parent only places it.\n */\nconst PLACEMENT =\n /^(position|inset|left|top|right|bottom|(min-|max-)?(width|height)|margin(-.+)?|flex(-(grow|shrink|basis))?|align-self|justify-self|order|grid-(area|column|row)(-.+)?|transform(-origin)?|rotate|translate|scale|z-index)$/\n\n/** Whether a declaration places a layer rather than drawing it. */\nexport const isPlacement = (property: string) => PLACEMENT.test(property)\n\n/** Whether a declaration hides or shows a layer by state, which the parent decides too. */\nconst isVisibility = (property: string, value: string) =>\n property === 'display' && (value === 'none' || value === 'revert')\n\n/** Keeps only where the parent places a layer, and whether a state shows it. */\nexport function placementOnly(element: StateElement): void {\n const placement = (style: DesignStyleDeclaration): DesignStyleDeclaration =>\n Object.fromEntries(\n Object.entries(style).filter(\n ([property, value]) => isPlacement(property) || isVisibility(property, value)\n )\n )\n element.base = placement(element.base)\n element.rules = element.rules\n .map((rule) => ({ ...rule, style: placement(rule.style) }))\n .filter((rule) => !isEmptyObject(rule.style))\n}\n\n/** Generated components by the id of the set they come from, which instances refer to. */\nexport type ComponentReferences = ReadonlyMap<string, ComponentModel>\n\n/** The set a component belongs to, or the component itself when it stands alone. */\nfunction ownerId(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.id : component.id\n}\n\n/**\n * The words an instance shows for a text property: an assignment that overrides the default,\n * else what its bound text layer reads, which a direct edit changes, else the assignment.\n */\nexport function shownText(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): string | undefined {\n const assigned = instance.componentPropertyAssignments[propertyId]\n const main = instanceMainComponent(graph, instance)\n const owner = main && behaviourOwner(graph, main)\n const definition = owner?.componentPropertyDefinitions.find((item) => item.id === propertyId)\n if (typeof assigned === 'string' && assigned !== definition?.defaultValue) return assigned\n const target = findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.field === 'TEXT' && item.node.type === 'TEXT'\n )\n return target?.node.text ?? (typeof assigned === 'string' ? assigned : undefined)\n}\n\n/**\n * What `instance` sets on `component`: the values it is drawn with that differ from defaults,\n * and whether it is drawn on: its model, or for a group's item the value that marks it chosen.\n */\nexport function referenceValues(\n graph: SceneGraph,\n instance: SceneNode,\n component: ComponentModel\n): Pick<ComponentReference, 'props' | 'model'> {\n const values = instanceMainComponent(graph, instance)?.componentPropertyValues ?? {}\n const props: ReferenceProp[] = []\n let model: string | null = null\n for (const [property, arg] of component.args.booleans) {\n if (values[property] !== arg.on) continue\n const on = arg.name === component.model || (component.valueProp && arg.name !== 'disabled')\n if (on) model = arg.name\n else props.push({ name: arg.name, value: true })\n }\n const states = component.args.states\n if (states?.disabled && values[states.property] === states.disabled)\n props.push({ name: 'disabled', value: true })\n for (const prop of component.props) {\n const value = values[prop.property]\n if (Object.hasOwn(values, prop.property) && value !== prop.default)\n props.push({ name: prop.name, value })\n }\n for (const text of component.texts) {\n const value = shownText(graph, instance, text.id)\n if (value !== undefined && value !== text.default) props.push({ name: text.name, value })\n }\n for (const prop of component.booleans) {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, prop.id)\n ? assignments[prop.id] === 'true'\n : prop.default\n if (value !== prop.default) props.push({ name: prop.name, value })\n }\n return { props, model }\n}\n\n/** A used layer, before the parent's class name for it is known. */\nexport type UsedLayer = Omit<ComponentReference, 'className'> | Omit<IconReference, 'className'>\n\n/**\n * What the layer at `element` uses in place of drawing itself, if anything, read from the first\n * variant that draws it as that element: the rest state, or the one that shows it, such as open\n * content.\n */\nfunction usedLayer(\n graph: SceneGraph,\n variantIds: readonly string[],\n element: StateElement,\n references: ComponentReferences\n): UsedLayer | null {\n const path = element.key.split('\\0')[0] ?? ''\n // The variant's layer at that path drawn as this element is: a frame, or that instance or icon.\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found !== undefined && layerKind(graph, found) === element.kind)\n if (!node) return null\n const main = node.type === 'INSTANCE' ? instanceMainComponent(graph, node) : undefined\n // An instance changed beyond its properties draws its own layers, which the component's\n // props could not reproduce.\n const component =\n main && drawsAsMain(graph, node, main) ? references.get(ownerId(graph, main)) : undefined\n if (component)\n return {\n type: 'reference',\n component: component.name,\n ...referenceValues(graph, node, component)\n }\n const icon = readIcon(node)\n return icon && isNamedIcon(icon) && !isIconModified(graph, node)\n ? { type: 'icon', icon: icon.name }\n : null\n}\n\n/**\n * The layers of a set's merged markup that are used rather than drawn: instances of other\n * generated components, and icons from a set, read from the variants in order, the rest state\n * first. Their own layers are dropped from the markup and the styles, which belong to the\n * component or the icon.\n */\nexport function referencedLayers(\n graph: SceneGraph,\n root: StateElement,\n variantIds: readonly string[],\n references: ComponentReferences,\n /** Layers already used otherwise, such as a group's items. */\n taken: ReadonlyMap<StateElement, unknown> = new Map()\n): Map<StateElement, UsedLayer> {\n const used = new Map<StateElement, UsedLayer>()\n const visit = (element: StateElement) => {\n for (const child of element.children) {\n if (child.type !== 'element' || taken.has(child)) continue\n const layer = usedLayer(graph, variantIds, child, references)\n if (!layer) {\n visit(child)\n continue\n }\n used.set(child, layer)\n child.children = []\n if (layer.type === 'reference') placementOnly(child)\n }\n }\n visit(root)\n return used\n}\n","import { difference } from '#dom-css/behaviours/states/model'\nimport type { StateElement, StateNode } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\nimport { kebabCase } from 'es-toolkit/string'\n\nimport { claimName } from '../storybook/names'\nimport { isPlacement } from './references'\n\n/** A layer drawn once per value, such as a tab's trigger or its panel, and the value it is. */\nexport interface RepeatedPart {\n part: string\n value: string\n}\n\n/**\n * The string a component chooses among, such as the open tab, and the one it starts on, or\n * none, as a radio group with no item chosen.\n */\nexport interface ChoiceModel {\n options: string[]\n default: string | null\n}\n\n/** The words a layer reads, joined across its text. */\nexport function textOf(node: StateNode): string {\n if (node.type === 'text') return node.text\n return node.children.map(textOf).join(' ')\n}\n\nconst elementsOf = (element: StateElement | undefined) =>\n (element?.children ?? []).filter((child): child is StateElement => child.type === 'element')\n\n/**\n * The value each label stands for: the label as a slug, such as `account`, apart from the\n * others, or its position when it has no words.\n */\nexport function slugValues(labels: readonly string[]): string[] {\n const taken = new Set<string>()\n return labels.map((label, index) => claimName(kebabCase(label) || String(index), taken))\n}\n\n/**\n * Tabs' triggers, the layers in its list, and its panels, the layers in its panels slot, each\n * with the value of the tab it belongs to, matched by position. The tabs start on the first.\n */\nexport function tabParts(\n parts: ReadonlyMap<StateElement, string>,\n variantOptions: readonly string[] = []\n): {\n repeated: Map<StateElement, RepeatedPart>\n choice: ChoiceModel | null\n} {\n const partElement = (id: string) => [...parts].find(([, part]) => part === id)?.[0]\n const triggers = elementsOf(partElement('list'))\n const drawn = slugValues(triggers.map(textOf))\n // A choice bound to a variant property names each trigger by that property's option.\n const values = variantOptions.length === triggers.length ? [...variantOptions] : drawn\n const repeated = new Map<StateElement, RepeatedPart>()\n for (const [index, trigger] of triggers.entries())\n repeated.set(trigger, { part: 'trigger', value: values[index] ?? String(index) })\n for (const [index, panel] of elementsOf(partElement('panels')).entries()) {\n const value = values.at(index)\n if (value !== undefined) repeated.set(panel, { part: 'content', value })\n }\n const first = values.at(0)\n return { repeated, choice: first === undefined ? null : { options: values, default: first } }\n}\n\n/** How `drawn` looks different from `base`, leaving out where each is placed. */\nfunction lookChange(\n base: DesignStyleDeclaration,\n drawn: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const changed = Object.entries(difference(base, drawn))\n return Object.fromEntries(changed.filter(([property]) => !isPlacement(property)))\n}\n\n/** `base` with `change` applied, where `unset` drops a declaration. */\nfunction applied(\n base: DesignStyleDeclaration,\n change: DesignStyleDeclaration\n): DesignStyleDeclaration {\n return Object.fromEntries([\n ...Object.entries(base).filter(([property]) => change[property] !== 'unset'),\n ...Object.entries(change).filter(([, value]) => value !== 'unset')\n ])\n}\n\n/** The layer of `into` where `from` has `child`: the same name, and the same one of that name. */\nfunction counterpart(\n child: StateElement,\n from: StateElement,\n into: StateElement\n): StateElement | undefined {\n const named = (element: StateElement) =>\n elementsOf(element).filter((item) => item.name === child.name)\n return named(into).at(named(from).indexOf(child))\n}\n\n/**\n * Tabs draw the first trigger chosen and the others not. Every trigger rests with the look of\n * the others and takes the first one's, layer by layer, while Reka or Radix marks it active;\n * each keeps its own place. A layer is matched across triggers by name, and one without a\n * counterpart keeps its own styles.\n */\nexport function activeTriggers(repeated: ReadonlyMap<StateElement, RepeatedPart>): void {\n const triggers = [...repeated].filter(([, item]) => item.part === 'trigger').map(([el]) => el)\n const first = triggers.at(0)\n const second = triggers.at(1)\n if (!first || !second) return\n // The two looks as drawn, before the first trigger rests with the others' look.\n const [active, inactive] = structuredClone([first, second])\n for (const trigger of triggers) {\n const visit = (layer: StateElement, drawn: StateElement, other: StateElement) => {\n if (trigger === first) layer.base = applied(layer.base, lookChange(drawn.base, other.base))\n // From the layer's own rest, so a trigger drawn apart still takes the chosen look.\n const look = lookChange(layer.base, drawn.base)\n if (!isEmptyObject(look))\n layer.rules.push({\n conditions: [{ type: 'state', value: 'active' }],\n on: trigger,\n style: look\n })\n for (const child of elementsOf(layer)) {\n const drawnChild = counterpart(child, layer, drawn)\n const otherChild = counterpart(child, layer, other)\n if (drawnChild && otherChild) visit(child, drawnChild, otherChild)\n }\n }\n visit(trigger, active, inactive)\n }\n}\n","import type { StateElement } from '#dom-css/behaviours/states/types'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport type { ComponentModel } from './model'\nimport { placementOnly, referenceValues, shownText, type UsedLayer } from './references'\nimport { slugValues, textOf, type ChoiceModel } from './repeats'\n\n/** Groups whose items are their own primitive inside the group, as Reka and Radix have them. */\nexport const GROUP_ITEMS = {\n radioGroup: 'radioGroupItem',\n toggleGroup: 'toggleGroupItem',\n accordion: 'accordionItem'\n} as const\n\nexport type GroupKind = keyof typeof GROUP_ITEMS\nexport type ItemKind = (typeof GROUP_ITEMS)[GroupKind]\n\nexport const isGroup = (kind: string): kind is GroupKind => Object.hasOwn(GROUP_ITEMS, kind)\n\n/** Builds the component of a group's items, named for the group. */\nexport type ItemBuilder = (owner: SceneNode) => ComponentModel | null\n\n/**\n * A group's items: the component they share, generated as the group's item primitive, and\n * each item in the items slot as a use of it with the value it stands for. The group chooses\n * among those values, starting on the item the design draws on, or none.\n */\nexport function groupItems(\n graph: SceneGraph,\n variantIds: readonly string[],\n itemsElement: StateElement | undefined,\n build: ItemBuilder\n): { item: ComponentModel; used: Map<StateElement, UsedLayer>; choice: ChoiceModel } | null {\n const elements = (itemsElement?.children ?? []).filter(\n (child): child is StateElement => child.type === 'element'\n )\n const instances = elements.map((element) => {\n const path = element.key.split('\\0')[0] ?? ''\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found?.type === 'INSTANCE')\n const main = node && instanceMainComponent(graph, node)\n return node && main ? { node, owner: behaviourOwner(graph, main) } : null\n })\n const owner = instances.find((instance) => instance?.owner)?.owner\n const item = owner && build(owner)\n if (!owner || !item) return null\n\n // An item is named by its label property when it has one, else by the words it reads.\n const label = item.texts.at(0)\n const values = slugValues(\n elements.map((element, index) => {\n const node = instances[index]?.node\n return (label && node && shownText(graph, node, label.id)) || textOf(element)\n })\n )\n const used = new Map<StateElement, UsedLayer>()\n let chosen: string | null = null\n for (const [index, element] of elements.entries()) {\n const instance = instances[index]\n const value = values.at(index)\n if (instance?.owner?.id !== owner.id || value === undefined) continue\n const { props, model } = referenceValues(graph, instance.node, item)\n if (model) chosen ??= value\n used.set(element, {\n type: 'reference',\n component: item.name,\n props: [{ name: 'value', value }, ...props],\n model: null\n })\n element.children = []\n placementOnly(element)\n }\n return { item, used, choice: { options: values, default: chosen } }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmDA,MAAM,YACJ;;AAGF,MAAa,eAAe,aAAqB,UAAU,KAAK,QAAQ;;AAGxE,MAAM,gBAAgB,UAAkB,UACtC,aAAa,cAAc,UAAU,UAAU,UAAU;;AAG3D,SAAgB,cAAc,SAA6B;CACzD,MAAM,aAAa,UACjB,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,CAAC,UAAU,WAAW,YAAY,QAAQ,KAAK,aAAa,UAAU,KAAK,CAC9E,CACF;CACF,QAAQ,OAAO,UAAU,QAAQ,IAAI;CACrC,QAAQ,QAAQ,QAAQ,MACrB,KAAK,UAAU;EAAE,GAAG;EAAM,OAAO,UAAU,KAAK,KAAK;CAAE,EAAE,CAAC,CAC1D,QAAQ,SAAS,CAAC,cAAc,KAAK,KAAK,CAAC;AAChD;;AAMA,SAAS,QAAQ,OAAmB,WAA8B;CAChE,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,QAAQ,SAAS,kBAAkB,OAAO,KAAK,UAAU;AAClE;;;;;AAMA,SAAgB,UACd,OACA,UACA,YACoB;CACpB,MAAM,WAAW,SAAS,6BAA6B;CACvD,MAAM,OAAO,sBAAsB,OAAO,QAAQ;CAElD,MAAM,cADQ,QAAQ,eAAe,OAAO,IAAI,EAA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UAAU;EAC/B,MAAM,OAAO,UAAU,MAAM,EAAE;EAC/B,OAAQ,SAAS,QAAQ,UAAU,OAAO,MAAM,MAAM,EAAE,KAAM,OAAO,OAAO;CAC9E,CAAC,CACH;CACA,MAAM,uBAAO,IAAI,IAA6B;CAC9C,IAAI,SAAwB;CAC5B,KAAK,MAAM,CAAC,OAAO,YAAY,SAAS,QAAQ,GAAG;EACjD,MAAM,WAAW,UAAU;EAC3B,MAAM,QAAQ,OAAO,GAAG,KAAK;EAC7B,IAAI,UAAU,OAAO,OAAO,MAAM,MAAM,UAAU,KAAA,GAAW;EAC7D,MAAM,EAAE,OAAO,UAAU,gBAAgB,OAAO,SAAS,MAAM,IAAI;EACnE,IAAI,OAAO,WAAW;EACtB,KAAK,IAAI,SAAS;GAChB,MAAM;GACN,WAAW,KAAK;GAChB,OAAO,CAAC;IAAE,MAAM;IAAS;GAAM,GAAG,GAAG,KAAK;GAC1C,OAAO;EACT,CAAC;EACD,QAAQ,WAAW,CAAC;EACpB,cAAc,OAAO;CACvB;CACA,OAAO;EAAE;EAAM;EAAM,QAAQ;GAAE,SAAS;GAAQ,SAAS;EAAO;CAAE;AACpE"}
|
|
@@ -11,7 +11,7 @@ import { drawingImports, iconDrawing, iconImportDeclarations, iconNamer } from "
|
|
|
11
11
|
import { isShaderPresetPaint, shaderOfPaint } from "@pairdraw/scene-graph/shaders";
|
|
12
12
|
import { compact, uniq, zip } from "es-toolkit/array";
|
|
13
13
|
import { omit } from "es-toolkit/object";
|
|
14
|
-
import { behaviourContract, behaviourProperties, findLayerByPath, layerPath, readBehaviour, textBinding } from "@pairdraw/scene-graph/behaviours";
|
|
14
|
+
import { behaviourContract, behaviourProperties, booleanBinding, findLayerByPath, layerPath, readBehaviour, textBinding } from "@pairdraw/scene-graph/behaviours";
|
|
15
15
|
import { slotPropertyId } from "@pairdraw/scene-graph/slots";
|
|
16
16
|
import { variantDefaultValue } from "@pairdraw/scene-graph/components";
|
|
17
17
|
import { camelCase, kebabCase, upperFirst } from "es-toolkit/string";
|
|
@@ -239,6 +239,14 @@ const GENERATED_KINDS = [
|
|
|
239
239
|
"textField",
|
|
240
240
|
"textarea"
|
|
241
241
|
];
|
|
242
|
+
/**
|
|
243
|
+
* Whether a field's markup always draws its input, which then takes the caller's attributes. A
|
|
244
|
+
* field whose text is not bound yet has none, and an input inside a slot is replaced when the
|
|
245
|
+
* caller fills the slot; the root takes the attributes then.
|
|
246
|
+
*/
|
|
247
|
+
function drawsInput(node) {
|
|
248
|
+
return node.children.some((child) => child.type === "input" || child.type === "element" && !child.slot && drawsInput(child));
|
|
249
|
+
}
|
|
242
250
|
/** Parts each kind renders as a native button, which the reset clears for the design. */
|
|
243
251
|
const BUTTON_PARTS = {
|
|
244
252
|
button: ["root"],
|
|
@@ -278,6 +286,11 @@ function partPaths(graph, set, behaviour) {
|
|
|
278
286
|
for (const variant of ownerVariants(graph, set)) for (const child of graph.getChildren(variant.id)) visit(variant, child);
|
|
279
287
|
return paths;
|
|
280
288
|
}
|
|
289
|
+
/** The variant props a component takes, without the property its choice draws. */
|
|
290
|
+
function choiceProps(graph, set, args, taken, choice) {
|
|
291
|
+
taken.add(choice?.name ?? "");
|
|
292
|
+
return variantProps(graph, set, args, taken).filter((prop) => prop.property !== choice?.name);
|
|
293
|
+
}
|
|
281
294
|
/** Each layer's behaviour part: the root, and the slot frames that draw the others. */
|
|
282
295
|
function behaviourParts(graph, set, behaviour, root) {
|
|
283
296
|
const paths = partPaths(graph, set, behaviour);
|
|
@@ -312,12 +325,17 @@ function variantProps(graph, set, args, taken) {
|
|
|
312
325
|
}));
|
|
313
326
|
}
|
|
314
327
|
/** What the root binds: its model, an item's value, `disabled`, and its variant props. */
|
|
315
|
-
function rootBindings(model, item, disabled, props) {
|
|
328
|
+
function rootBindings(model, item, disabled, props, choice) {
|
|
316
329
|
return [
|
|
317
330
|
...model ? [{
|
|
318
331
|
type: "model",
|
|
319
332
|
name: model
|
|
320
333
|
}] : [],
|
|
334
|
+
...model && choice ? [{
|
|
335
|
+
type: "modelProp",
|
|
336
|
+
name: model,
|
|
337
|
+
attribute: choice.attribute
|
|
338
|
+
}] : [],
|
|
321
339
|
...item ? [{ type: "value" }] : [],
|
|
322
340
|
...disabled ? [{ type: "disabled" }] : [],
|
|
323
341
|
...props.map((prop) => ({
|
|
@@ -378,7 +396,9 @@ function borderBoxes(root) {
|
|
|
378
396
|
*/
|
|
379
397
|
function drawnParts(graph, set, behaviour, kind, root) {
|
|
380
398
|
const parts = behaviour ? behaviourParts(graph, set, behaviour, root) : /* @__PURE__ */ new Map([[root, "root"]]);
|
|
381
|
-
const
|
|
399
|
+
const choiceBinding = behaviour?.kind === "tabs" ? booleanBinding(behaviour, "value") : void 0;
|
|
400
|
+
const choiceProperty = choiceBinding ? behaviourProperties(graph, set).find((item) => item.id === choiceBinding.propertyId && item.type === "VARIANT") : void 0;
|
|
401
|
+
const tabs = behaviour?.kind === "tabs" ? tabParts(parts, choiceProperty?.variantOptions ?? []) : null;
|
|
382
402
|
const repeated = tabs?.repeated ?? /* @__PURE__ */ new Map();
|
|
383
403
|
activeTriggers(repeated);
|
|
384
404
|
resetButtons(kind, parts, repeated);
|
|
@@ -388,7 +408,8 @@ function drawnParts(graph, set, behaviour, kind, root) {
|
|
|
388
408
|
return {
|
|
389
409
|
parts,
|
|
390
410
|
tabs,
|
|
391
|
-
repeated
|
|
411
|
+
repeated,
|
|
412
|
+
choiceProperty
|
|
392
413
|
};
|
|
393
414
|
}
|
|
394
415
|
/** The number or text the component holds, and the text property a field's input shows. */
|
|
@@ -414,7 +435,7 @@ function componentModel(graph, set, options = {}) {
|
|
|
414
435
|
const args = behaviourArgs(graph, set) ?? { booleans: /* @__PURE__ */ new Map() };
|
|
415
436
|
if (!kind || !styles) return null;
|
|
416
437
|
const name = options.name ?? identifierName(set.name, "Component");
|
|
417
|
-
const { parts, tabs, repeated } = drawnParts(graph, set, behaviour, kind, styles.root);
|
|
438
|
+
const { parts, tabs, repeated, choiceProperty } = drawnParts(graph, set, behaviour, kind, styles.root);
|
|
418
439
|
const variantIds = [styles.restId, ...ownerVariants(graph, set).map((variant) => variant.id)];
|
|
419
440
|
const items = behaviour && itemsOf(graph, behaviour, variantIds, parts, options, (itemOf) => (owner) => componentModel(graph, owner, {
|
|
420
441
|
...options,
|
|
@@ -430,7 +451,7 @@ function componentModel(graph, set, options = {}) {
|
|
|
430
451
|
"disabled",
|
|
431
452
|
"value"
|
|
432
453
|
]);
|
|
433
|
-
const props =
|
|
454
|
+
const props = choiceProps(graph, set, args, taken, choiceProperty);
|
|
434
455
|
const disabled = drawsDisabled(args);
|
|
435
456
|
const used = usedLayers(graph, styles.root, variantIds, items?.used, options.references);
|
|
436
457
|
const elements = allElements(styles.root);
|
|
@@ -454,7 +475,10 @@ function componentModel(graph, set, options = {}) {
|
|
|
454
475
|
slotOf,
|
|
455
476
|
shaders: shaderLayers(graph, styles.restId, elements),
|
|
456
477
|
layerOf: (element) => restLayerOf(graph, styles, element)
|
|
457
|
-
}, rootBindings(model, !!options.itemOf, disabled, props
|
|
478
|
+
}, rootBindings(model, !!options.itemOf, disabled, props, choiceProperty && {
|
|
479
|
+
name: choiceProperty.name,
|
|
480
|
+
attribute: propAttribute(choiceProperty.name)
|
|
481
|
+
})),
|
|
458
482
|
model,
|
|
459
483
|
choice,
|
|
460
484
|
range,
|
|
@@ -952,6 +976,7 @@ function rootAttributes(uses) {
|
|
|
952
976
|
function bindingAttributes$1(node, kind, native) {
|
|
953
977
|
return node.bindings.flatMap((binding) => {
|
|
954
978
|
if (binding.type === "prop") return [jsx.attribute(binding.attribute, jsx.container(es.identifier(binding.prop.name)))];
|
|
979
|
+
if (binding.type === "modelProp") return [jsx.attribute(binding.attribute, jsx.container(es.parseExpression(`props.${binding.name}`)))];
|
|
955
980
|
if (binding.type === "disabled" && native) return [jsx.attribute("data-disabled", jsx.container(disabledFlag(kind)))];
|
|
956
981
|
return [];
|
|
957
982
|
});
|
|
@@ -1199,8 +1224,20 @@ const REKA = {
|
|
|
1199
1224
|
textarea: { parts: {} },
|
|
1200
1225
|
plain: { parts: {} }
|
|
1201
1226
|
};
|
|
1202
|
-
/**
|
|
1227
|
+
/**
|
|
1228
|
+
* Kinds whose two-way value is their input's, which binds it rather than the root. Their input
|
|
1229
|
+
* takes the caller's attributes too, such as `name` or `required`, and the root only `class`,
|
|
1230
|
+
* as the React components spread the caller's props on the input.
|
|
1231
|
+
*/
|
|
1203
1232
|
const INPUT_MODEL = /* @__PURE__ */ new Set(["textField", "textarea"]);
|
|
1233
|
+
/** Whether the caller's attributes go to the field's input: it is a field, and draws one. */
|
|
1234
|
+
const attrsToInput = (component) => INPUT_MODEL.has(component.kind) && drawsInput(component.tree);
|
|
1235
|
+
/** The caller's attributes but `class`, which the root takes, for a field's input. */
|
|
1236
|
+
const INPUT_ATTRS = es.parseExpression("{ ...$attrs, class: undefined }");
|
|
1237
|
+
/** The caller's `class`, which a field's root takes since its attributes go to the input. */
|
|
1238
|
+
const ROOT_CLASS = es.parseExpression("$attrs.class");
|
|
1239
|
+
/** The caller's attributes reach the input rather than falling through to the root. */
|
|
1240
|
+
const NO_ATTRS_FALLTHROUGH = es.parseModule("defineOptions({ inheritAttrs: false })");
|
|
1204
1241
|
/** What a group's root fixes: one item chosen at a time, and an accordion that can all close. */
|
|
1205
1242
|
const ROOT_ATTRIBUTES = {
|
|
1206
1243
|
toggleGroup: [vue.attribute("type", "single")],
|
|
@@ -1218,6 +1255,7 @@ function bindingAttributes(binding, uses, native) {
|
|
|
1218
1255
|
return [vue.model(identifier(bound), REKA[kind].model === "open" ? "open" : void 0)];
|
|
1219
1256
|
}
|
|
1220
1257
|
if (binding.type === "prop") return [vue.bound(binding.attribute, identifier(binding.prop.name))];
|
|
1258
|
+
if (binding.type === "modelProp") return [vue.bound(binding.attribute, identifier(binding.name))];
|
|
1221
1259
|
if (binding.type === "value") return [vue.bound("value", identifier("value"))];
|
|
1222
1260
|
return [...native && kind !== "button" ? [] : [vue.bound("disabled", identifier("disabled"))], ...native ? [vue.bound("data-disabled", DISABLED_FLAG)] : []];
|
|
1223
1261
|
}
|
|
@@ -1254,6 +1292,7 @@ function inputNode(className, uses) {
|
|
|
1254
1292
|
vue.attribute("class", uses.classOf(className)),
|
|
1255
1293
|
...component.model ? [vue.model(identifier(component.model))] : [],
|
|
1256
1294
|
...placeholder ? [vue.attribute("placeholder", placeholder)] : [],
|
|
1295
|
+
vue.spread(INPUT_ATTRS),
|
|
1257
1296
|
...component.disabled ? [vue.bound("disabled", identifier("disabled"))] : []
|
|
1258
1297
|
]);
|
|
1259
1298
|
}
|
|
@@ -1292,6 +1331,7 @@ function elementAttributes(node, uses, { native, button }) {
|
|
|
1292
1331
|
...uses.kind === "progress" && node.part === "indicator" ? progressStyle(uses.component) : [],
|
|
1293
1332
|
...Object.entries(omit(node.attrs, ["class"])).map(([name, value]) => vue.attribute(name, value)),
|
|
1294
1333
|
vue.attribute("class", compact([node.attrs.class, uses.classOf(node.className)]).join(" ")),
|
|
1334
|
+
...root && attrsToInput(uses.component) ? [vue.bound("class", ROOT_CLASS)] : [],
|
|
1295
1335
|
...node.value === void 0 ? [] : [vue.attribute("value", node.value)],
|
|
1296
1336
|
...node.bindings.flatMap((binding) => bindingAttributes(binding, uses, native))
|
|
1297
1337
|
];
|
|
@@ -1444,11 +1484,13 @@ function modelDeclaration(component, uses) {
|
|
|
1444
1484
|
function script(component, uses) {
|
|
1445
1485
|
const props = component.valueProp || hasDefaults(component) ? propsDeclaration(component) : [];
|
|
1446
1486
|
const refs = uses.models.flatMap((item) => es.fill(MODEL_REF, { $name: identifier(item.name) }).body);
|
|
1487
|
+
const options = attrsToInput(component) ? NO_ATTRS_FALLTHROUGH.body : [];
|
|
1447
1488
|
return {
|
|
1448
1489
|
type: "Program",
|
|
1449
1490
|
sourceType: "module",
|
|
1450
1491
|
body: [
|
|
1451
1492
|
...scriptImports(uses),
|
|
1493
|
+
...options,
|
|
1452
1494
|
...props,
|
|
1453
1495
|
...modelDeclaration(component, uses),
|
|
1454
1496
|
...refs
|