@wix/origami-transforms 0.1.33 → 0.1.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-transforms",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Babel and PostCSS checks and transforms for Wix origami page files.",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "@babel/parser": "^7.25.0",
21
21
  "@babel/types": "^7.25.2",
22
22
  "@wix/origami-fonts": "1.0.4",
23
- "@wix/origami-system-components": "1.10.6",
23
+ "@wix/origami-system-components": "1.10.7",
24
24
  "postcss": "^8.5.3",
25
25
  "postcss-custom-media": "^12.0.1",
26
26
  "@wix/origami-bi": "0.12.0"
@@ -75,5 +75,5 @@
75
75
  },
76
76
  "type": "module",
77
77
  "types": "./dist/index.d.ts",
78
- "falconPackageHash": "543337a557c7e9b34bf34978fb0fcde189ab7ccc51c0ee4a8e805448"
78
+ "falconPackageHash": "280462a4d30be30d58887ea92b2adc96a70bccc386eefaeff60065bc"
79
79
  }
@@ -5,7 +5,6 @@
5
5
  import { mediaValidationPlugin } from './mediaValidation/index.js'
6
6
  import { origamiCompatibilityPlugin } from './origamiCompatibility/index.js'
7
7
  import { layoutValidationPlugin } from './validation/index.js'
8
- import { pageSlotsPlugin } from './pageSlots.js'
9
8
 
10
9
  /** @type {readonly import('../transform/types.js').JsxTransformPlugin<string>[]} */
11
- export const jsxPlugins = Object.freeze([layoutValidationPlugin, mediaValidationPlugin, origamiCompatibilityPlugin, pageSlotsPlugin])
10
+ export const jsxPlugins = Object.freeze([layoutValidationPlugin, mediaValidationPlugin, origamiCompatibilityPlugin])
@@ -1,7 +0,0 @@
1
- /** @typedef {typeof checks[number]} Check */
2
- /** Transitional support for DM's literal Page children alongside authored slot props.
3
- * @type {import('../transform/types.js').JsxTransformPlugin<Check>} */
4
- export const pageSlotsPlugin: import("../transform/types.js").JsxTransformPlugin<Check>;
5
- export type Check = (typeof checks)[number];
6
- declare const checks: readonly [];
7
- export {};
@@ -1,90 +0,0 @@
1
- import { basename } from 'node:path'
2
- import { types as t } from '@babel/core'
3
- import { findAttribute } from './origamiCompatibility/ast.js'
4
-
5
- // Resolve imports rather than function names: shared definitions and wrapper names
6
- // are otherwise opaque to Page at runtime, especially after minification.
7
- const componentOf = path => {
8
- const name = path.node.openingElement.name
9
- if (!t.isJSXIdentifier(name)) return undefined
10
- const binding = path.scope.getBinding(name.name)?.path
11
- if (!binding || !binding.parentPath.isImportDeclaration()) return undefined
12
- const source = binding.parentPath.node.source.value
13
- const imported = binding.isImportSpecifier()
14
- ? binding.node.imported.name ?? binding.node.imported.value
15
- : 'default'
16
- if (source === 'document' || source === 'document/components' || source === 'wixSystemElements') {
17
- return imported
18
- }
19
- const system = /^@wix\/origami-system-components\/layout\/(Page|Header|Footer)$/u.exec(source)?.[1]
20
- if (system && (imported === system || imported === 'default')) return system
21
- const shared = /(?:^|\/)global\/components\/(Header|Footer)_[^/]+(?:\/index\.jsx)?$/u.exec(source)?.[1]
22
- if (shared && imported === 'default') return shared
23
- const background = /^@origami-wrappers\/wixSystemElements\/(background|backgroundshapedivider)$/u.exec(source)?.[1]
24
- if (background && (imported.toLowerCase() === background || imported === 'default')) return 'Background'
25
- return undefined
26
- }
27
-
28
- const slotFor = component => {
29
- if (component === 'Header' || component?.startsWith('Header_')) return 'header'
30
- if (component === 'Footer' || component?.startsWith('Footer_')) return 'footer'
31
- if (component === 'Background' || component === 'BackgroundShapeDivider') return 'backgroundLayer'
32
- return undefined
33
- }
34
-
35
- const checks = /** @type {const} */ ([])
36
- /** @typedef {typeof checks[number]} Check */
37
-
38
- /** Transitional support for DM's literal Page children alongside authored slot props.
39
- * @type {import('../transform/types.js').JsxTransformPlugin<Check>} */
40
- export const pageSlotsPlugin = {
41
- checks,
42
- name: 'wix-import-page-slots',
43
- order: 0,
44
- appliesTo: context => basename(context.filePath) === 'structure.jsx',
45
- transform: program => {
46
- program.traverse({
47
- JSXElement(path) {
48
- if (componentOf(path) !== 'Page') return
49
- const slots = new Map()
50
- const collect = parent => {
51
- for (const child of parent.get('children')) {
52
- if (child.isJSXFragment()) {
53
- collect(child)
54
- continue
55
- }
56
- if (!child.isJSXElement()) continue
57
- const slot = slotFor(componentOf(child))
58
- if (!slot) continue
59
- if (!slots.has(slot)) slots.set(slot, [])
60
- slots.get(slot).push(child.node)
61
- child.remove()
62
- }
63
- }
64
- collect(path)
65
- const attributes = path.node.openingElement.attributes
66
- for (const [slot, children] of slots) {
67
- // Explicit slots (including null) win. Insert defaults before spreads
68
- // so an authored spread can override them as normal JSX props do.
69
- if (findAttribute(attributes, slot)) continue
70
- let value
71
- if (slot === 'backgroundLayer') {
72
- // The slot shares InternalContainer's array contract. These
73
- // literal children need keys now that they form an array.
74
- children.forEach((child, index) => {
75
- const props = child.openingElement.attributes
76
- if (!findAttribute(props, 'key')) {
77
- props.push(t.jsxAttribute(t.jsxIdentifier('key'), t.stringLiteral(`origami-background-${index}`)))
78
- }
79
- })
80
- value = t.arrayExpression(children)
81
- } else {
82
- value = children.length === 1 ? children[0] :
83
- t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), children)
84
- }
85
- attributes.unshift(t.jsxAttribute(t.jsxIdentifier(slot), t.jsxExpressionContainer(value)))
86
- }
87
- },
88
- })
89
- },
90
- }