@adobe-commerce/elsie 1.5.0-beta2 → 1.6.0-alpha999

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.
@@ -4,7 +4,9 @@ const path = require('path');
4
4
  module.exports = async function generateResourceBuilder({ argv }) {
5
5
  const { build, preview } = await import('vite');
6
6
 
7
- const configFile = argv?.config ?? path.resolve(__dirname, '../../../config/vite.mjs');
7
+ const configFile =
8
+ argv?.config ??
9
+ path.resolve(...[__dirname, '..', '..', '..', 'config', 'vite.mjs']);
8
10
 
9
11
  let built = false;
10
12
 
package/config/vite.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  import { glob } from 'glob';
@@ -25,7 +25,12 @@ import banner from 'vite-plugin-banner';
25
25
  const env = loadEnv('', process.cwd());
26
26
 
27
27
  // Load Elsie Config
28
- const elsieConfig = await import(path.resolve(process.cwd(), './.elsie.js')).then((m) => m.default);
28
+ const elsieConfigPath = path.resolve(process.cwd(), './.elsie.js');
29
+ // Convert Windows paths to file:// URLs for ES module imports
30
+ const elsieConfigUrl = elsieConfigPath.startsWith('file://')
31
+ ? elsieConfigPath
32
+ : `file://${elsieConfigPath.replace(/\\/g, '/')}`;
33
+ const elsieConfig = await import(elsieConfigUrl).then((m) => m.default);
29
34
 
30
35
  // Read package.json using createRequire (compatible with Node 20 and 22)
31
36
  const require = createRequire(import.meta.url);
@@ -293,19 +298,19 @@ export default {
293
298
  generateBundle(options, bundle) {
294
299
  for (const fileName in bundle) {
295
300
  const chunk = bundle[fileName];
296
-
301
+
297
302
  // Process both .map files and JS/TS files with sourcemaps
298
- if ((chunk.type === 'asset' && fileName.endsWith('.map')) ||
303
+ if ((chunk.type === 'asset' && fileName.endsWith('.map')) ||
299
304
  (chunk.type === 'chunk' && chunk.map)) {
300
305
  try {
301
306
  // Get the sourcemap object - either from the asset source or the chunk's map
302
307
  const map = chunk.type === 'asset' ? JSON.parse(chunk.source) : chunk.map;
303
-
308
+
304
309
  if (map.sources) {
305
310
  map.sources = map.sources.map((input) => {
306
311
  return input.replace(/(?:\.\.?\/)+src\//, `/${packageJSON.name}/src/`);
307
312
  });
308
-
313
+
309
314
  // Update the sourcemap in the appropriate place
310
315
  if (chunk.type === 'asset') {
311
316
  chunk.source = JSON.stringify(map);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/elsie",
3
- "version": "1.5.0-beta2",
3
+ "version": "1.6.0-alpha999",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Domain Package SDK",
6
6
  "engines": {
@@ -32,6 +32,12 @@ The `<Slot />` component is used to define a slot in a container. It receives a
32
32
 
33
33
  The name of the slot in _PascalCase_. `string` (required).
34
34
 
35
+ ### lazy
36
+
37
+ Controls whether the slot should be loaded immediately or deferred for later initialization. `boolean` (optional).
38
+
39
+ When `lazy={false}`, the slot is initialized as soon as the container mounts. When `lazy={true}`, the slot can be initialized later on when it is needed. This is useful for performance optimization, especially when the slot's content is not immediately required.
40
+
35
41
  ### slotTag
36
42
 
37
43
  The HTML tag to use for the slot's wrapper element. This allows you to change the wrapper element from the default `div` to any valid HTML tag (e.g., 'span', 'p', 'a', etc.). When using specific tags like 'a', you can also provide their respective HTML attributes (e.g., 'href', 'target', etc.).
@@ -71,7 +77,7 @@ Example:
71
77
 
72
78
  - `ctx`: An object representing the context of the slot, including methods for manipulating the slot's content.
73
79
 
74
- The slot property, which is implemented as a promise function, provides developers with the flexibility to dynamically generate and manipulate content within slots.
80
+ The slot property, which is implemented as a promise function, provides developers with the flexibility to dynamically generate and manipulate content within slots.
75
81
  However, it's important to note that this promise is render-blocking, meaning that the component will not render until the promise is resolved.
76
82
 
77
83
  ### context
package/src/lib/slot.tsx CHANGED
@@ -2,30 +2,35 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
- import { cloneElement, ComponentChildren, RefObject, VNode, createElement } from 'preact';
10
+ import { IntlContext, Lang } from '@adobe-commerce/elsie/i18n';
11
+ import {
12
+ cloneElement,
13
+ ComponentChildren,
14
+ createElement,
15
+ RefObject,
16
+ VNode,
17
+ } from 'preact';
18
+ import { HTMLAttributes } from 'preact/compat';
11
19
  import {
12
20
  StateUpdater,
21
+ useCallback,
13
22
  useContext,
14
- useState,
15
- useRef,
16
23
  useEffect,
17
24
  useMemo,
18
- useCallback,
25
+ useRef,
26
+ useState,
19
27
  } from 'preact/hooks';
20
- import { IntlContext, Lang } from '@adobe-commerce/elsie/i18n';
21
- import { HTMLAttributes } from 'preact/compat';
22
28
  import { SlotQueueContext } from './render';
23
29
 
24
30
  import '@adobe-commerce/elsie/components/UIProvider/debugger.css';
25
31
 
26
32
  type MutateElement = (elem: HTMLElement) => void;
27
33
 
28
-
29
34
  interface State {
30
35
  get: (key: string) => void;
31
36
  set: (key: string, value: any) => void;
@@ -149,18 +154,21 @@ export function useSlot<K, V extends HTMLElement>(
149
154
  // @ts-ignore
150
155
  context._registerMethod = _registerMethod;
151
156
 
152
- const _htmlElementToVNode = useCallback((elem: HTMLElement) => {
153
- return createElement(
154
- contentTag,
155
- {
156
- 'data-slot-html-element': elem.tagName.toLowerCase(),
157
- ref: (refElem: HTMLElement | null): void => {
158
- refElem?.appendChild(elem);
159
- }
160
- },
161
- null
162
- );
163
- }, [contentTag]);
157
+ const _htmlElementToVNode = useCallback(
158
+ (elem: HTMLElement) => {
159
+ return createElement(
160
+ contentTag,
161
+ {
162
+ 'data-slot-html-element': elem.tagName.toLowerCase(),
163
+ ref: (refElem: HTMLElement | null): void => {
164
+ refElem?.appendChild(elem);
165
+ },
166
+ },
167
+ null
168
+ );
169
+ },
170
+ [contentTag]
171
+ );
164
172
 
165
173
  // @ts-ignore
166
174
  context._htmlElementToVNode = _htmlElementToVNode;
@@ -322,7 +330,10 @@ export function useSlot<K, V extends HTMLElement>(
322
330
  status.current = 'loading';
323
331
 
324
332
  log(`🟩 "${name}" Slot Initialized`);
325
- await callback(context as K & DefaultSlotContext<K>, elementRef.current as HTMLDivElement | null);
333
+ await callback(
334
+ context as K & DefaultSlotContext<K>,
335
+ elementRef.current as HTMLDivElement | null
336
+ );
326
337
  } catch (error) {
327
338
  console.error(`Error in "${callback.name}" Slot callback`, error);
328
339
  } finally {
@@ -336,7 +347,7 @@ export function useSlot<K, V extends HTMLElement>(
336
347
  // Initialization
337
348
  useEffect(() => {
338
349
  handleLifeCycleInit().finally(() => {
339
- if (slotsQueue) {
350
+ if (slotsQueue && slotsQueue.value.has(name)) {
340
351
  slotsQueue.value.delete(name);
341
352
  slotsQueue.value = new Set(slotsQueue.value);
342
353
  }
@@ -359,6 +370,7 @@ export function useSlot<K, V extends HTMLElement>(
359
370
  interface SlotPropsComponent<T>
360
371
  extends Omit<HTMLAttributes<HTMLElement>, 'slot'> {
361
372
  name: string;
373
+ lazy?: boolean;
362
374
  slot?: SlotProps<T>;
363
375
  context?: Context<T>;
364
376
  render?: (props: Record<string, any>) => VNode | VNode[];
@@ -371,6 +383,7 @@ interface SlotPropsComponent<T>
371
383
 
372
384
  export function Slot<T>({
373
385
  name,
386
+ lazy = false,
374
387
  context,
375
388
  slot,
376
389
  children,
@@ -400,11 +413,11 @@ export function Slot<T>({
400
413
  }
401
414
 
402
415
  // add slot to queue
403
- if (slotsQueue) {
416
+ if (slotsQueue && lazy === false) {
404
417
  slotsQueue.value.add(name);
405
418
  slotsQueue.value = new Set(slotsQueue.value);
406
419
  }
407
- }, [name, slotsQueue]);
420
+ }, [name, lazy, slotsQueue]);
408
421
 
409
422
  return createElement(
410
423
  slotTag,