@brytdesigns/web-component-core 1.1.1 → 1.1.3
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/esm/hooks/index.js +106 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/index.js +140 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.js +62 -13
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/main/hooks/index.d.ts +33 -0
- package/dist/main/hooks/index.js +3 -0
- package/dist/main/hooks/index.js.map +1 -0
- package/dist/main/hooks/internal/getValueFromPath.js +14 -0
- package/dist/main/hooks/internal/getValueFromPath.js.map +1 -0
- package/dist/main/hooks/internal/index.js +3 -0
- package/dist/main/hooks/internal/index.js.map +1 -0
- package/dist/main/hooks/makePathContextHooks.js +72 -0
- package/dist/main/hooks/makePathContextHooks.js.map +1 -0
- package/dist/main/index.d.ts +29 -2
- package/dist/main/index.js +1 -0
- package/dist/main/utils/createWithElementContext.js +21 -10
- package/dist/main/utils/createWithElementContext.js.map +1 -1
- package/dist/main/utils/formatValue.js +22 -0
- package/dist/main/utils/formatValue.js.map +1 -0
- package/dist/main/utils/index.d.ts +3 -1
- package/dist/main/utils/index.js +1 -0
- package/dist/main/utils/solid-element.js +20 -2
- package/dist/main/utils/solid-element.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createMemo } from 'solid-js';
|
|
2
|
+
import { createContext, provide, consume } from 'component-register';
|
|
3
|
+
import 'solid-js/web';
|
|
4
|
+
|
|
5
|
+
// src/hooks/makePathContextHooks.ts
|
|
6
|
+
|
|
7
|
+
// src/hooks/internal/getValueFromPath.ts
|
|
8
|
+
function getValueFromPath(obj, path) {
|
|
9
|
+
return path.split(".").reduce((acc, key) => {
|
|
10
|
+
if (acc === null || acc === void 0) return void 0;
|
|
11
|
+
const isArrayIndex = !isNaN(Number(key)) && key.trim() !== "";
|
|
12
|
+
if (Array.isArray(acc) && isArrayIndex) {
|
|
13
|
+
return acc[Number(key)];
|
|
14
|
+
}
|
|
15
|
+
return acc[key];
|
|
16
|
+
}, obj);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/utils/formatValue.ts
|
|
20
|
+
function formatValue(format, value) {
|
|
21
|
+
switch (format) {
|
|
22
|
+
case "currency":
|
|
23
|
+
if (typeof value === "number") return window.Shopify.formatMoney(value);
|
|
24
|
+
if (typeof value === "string")
|
|
25
|
+
return window.Shopify.formatMoney(parseFloat(value));
|
|
26
|
+
console.warn("formatValue: Unsupported value type for currency format.");
|
|
27
|
+
return window.Shopify.formatMoney(0);
|
|
28
|
+
case "number":
|
|
29
|
+
return Number(value);
|
|
30
|
+
case "boolean":
|
|
31
|
+
return Boolean(value);
|
|
32
|
+
case "invert_boolean":
|
|
33
|
+
return !Boolean(value);
|
|
34
|
+
default:
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/hooks/makePathContextHooks.ts
|
|
40
|
+
var makeFullPropertyPathContext = () => {
|
|
41
|
+
function createFullPathPropertyContext(options) {
|
|
42
|
+
return options.path;
|
|
43
|
+
}
|
|
44
|
+
const Context = createContext(createFullPathPropertyContext);
|
|
45
|
+
function provide$1({
|
|
46
|
+
element,
|
|
47
|
+
path
|
|
48
|
+
}) {
|
|
49
|
+
return provide(Context, { path }, element);
|
|
50
|
+
}
|
|
51
|
+
function useFullPropertyPathContext(context) {
|
|
52
|
+
return context;
|
|
53
|
+
}
|
|
54
|
+
function usePath(props) {
|
|
55
|
+
const context = consume(Context, props.element);
|
|
56
|
+
const basePath = useFullPropertyPathContext(context);
|
|
57
|
+
return createMemo(() => {
|
|
58
|
+
if (typeof basePath !== "function" && typeof props.path === "function") {
|
|
59
|
+
return props.path();
|
|
60
|
+
} else if (typeof basePath === "function" && typeof props.path !== "function") {
|
|
61
|
+
return basePath();
|
|
62
|
+
} else if (typeof basePath === "function" && typeof props.path === "function") {
|
|
63
|
+
return `${basePath()}.${props.path()}`;
|
|
64
|
+
}
|
|
65
|
+
return "";
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function usePathValue(options) {
|
|
69
|
+
return createMemo(() => {
|
|
70
|
+
const data = options.data();
|
|
71
|
+
if (typeof options.path !== "function") return data;
|
|
72
|
+
const path = options.path();
|
|
73
|
+
if (!path) return data;
|
|
74
|
+
const v = getValueFromPath(data, path);
|
|
75
|
+
if (v === void 0 || v === null) return null;
|
|
76
|
+
return v;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function useFormattedValue(options) {
|
|
80
|
+
const value = usePathValue({ path: options.path, data: options.data });
|
|
81
|
+
const formattedValue = createMemo(() => {
|
|
82
|
+
const v = value();
|
|
83
|
+
if (v === null) return null;
|
|
84
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
85
|
+
return formatValue(options.format || "", v);
|
|
86
|
+
}
|
|
87
|
+
console.warn(
|
|
88
|
+
options.element,
|
|
89
|
+
`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,
|
|
90
|
+
v
|
|
91
|
+
);
|
|
92
|
+
return null;
|
|
93
|
+
});
|
|
94
|
+
return formattedValue;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
provide: provide$1,
|
|
98
|
+
usePath,
|
|
99
|
+
usePathValue,
|
|
100
|
+
useFormattedValue
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { makeFullPropertyPathContext };
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/internal/getValueFromPath.ts","../../../src/utils/formatValue.ts","../../../src/hooks/makePathContextHooks.ts"],"names":["provide","_provide","_consume"],"mappings":";;;;;;;AA6BO,SAAS,gBAAA,CACd,KACA,IACiB,EAAA;AACjB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,IAAA;AAClB,MAAM,MAAA,CAAA,GAAI,gBAAiB,CAAA,IAAA,EAAM,IAAW,CAAA;AAC5C,MAAA,IAAI,CAAM,KAAA,MAAA,IAAa,CAAM,KAAA,IAAA,EAAa,OAAA,IAAA;AAC1C,MAAO,OAAA,CAAA;AAAA,KACR,CAAA;AAAA;AAUH,EAAA,SAAS,kBACP,OACkC,EAAA;AAClC,IAAM,MAAA,KAAA,GAAQ,aAAa,EAAE,IAAA,EAAM,QAAQ,IAAM,EAAA,IAAA,EAAM,OAAQ,CAAA,IAAA,EAAM,CAAA;AAErE,IAAM,MAAA,cAAA,GAAiB,WAAW,MAAM;AACtC,MAAA,MAAM,IAAI,KAAM,EAAA;AAChB,MAAI,IAAA,CAAA,KAAM,MAAa,OAAA,IAAA;AACvB,MACE,IAAA,OAAO,MAAM,QACb,IAAA,OAAO,MAAM,QACb,IAAA,OAAO,MAAM,SACb,EAAA;AACA,QAAA,OAAO,WAAY,CAAA,OAAA,CAAQ,MAAU,IAAA,EAAA,EAAI,CAAC,CAAA;AAAA;AAE5C,MAAQ,OAAA,CAAA,IAAA;AAAA,QACN,OAAQ,CAAA,OAAA;AAAA,QACR,CAAA,0FAAA,EAA6F,OAAO,CAAC,CAAA,CAAA,CAAA;AAAA,QACrG;AAAA,OACF;AACA,MAAO,OAAA,IAAA;AAAA,KACR,CAAA;AAED,IAAO,OAAA,cAAA;AAAA;AAGT,EAAO,OAAA;AAAA,aACLF,SAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["export type Path<T> = T extends readonly (infer U)[]\n ? `${number}` | `${number}.${Path<U>}` // Allows indexing into readonly arrays\n : T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object | any[]\n ? `${K}` | `${K}.${Path<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\nexport type PathValue<\n T,\n P extends string,\n> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : Key extends `${number}`\n ? T extends readonly (infer U)[]\n ? PathValue<U, Rest>\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${number}`\n ? T extends readonly (infer U)[]\n ? U\n : undefined\n : undefined;\n\nexport function getValueFromPath<T, P extends Path<T>>(\n obj: T,\n path: P\n): PathValue<T, P> {\n return path.split(\".\").reduce<any>((acc, key) => {\n if (acc === null || acc === undefined) return undefined;\n\n const isArrayIndex = !isNaN(Number(key)) && key.trim() !== \"\";\n if (Array.isArray(acc) && isArrayIndex) {\n return acc[Number(key)];\n }\n\n return acc[key];\n }, obj) as PathValue<T, P>;\n}\n","export type Format =\n | \"currency\"\n | \"number\"\n | \"boolean\"\n | \"invert_boolean\"\n | string;\n\nexport function formatValue(format: Format, value: unknown) {\n switch (format) {\n case \"currency\":\n if (typeof value === \"number\") return window.Shopify.formatMoney(value);\n if (typeof value === \"string\")\n return window.Shopify.formatMoney(parseFloat(value));\n console.warn(\"formatValue: Unsupported value type for currency format.\");\n return window.Shopify.formatMoney(0);\n case \"number\":\n return Number(value);\n case \"boolean\":\n return Boolean(value);\n case \"invert_boolean\":\n return !Boolean(value);\n default:\n return value as any;\n }\n}\n\ndeclare global {\n interface Window {\n Shopify: {\n formatMoney(value: number, currency?: string): string;\n };\n }\n}\n","import type { Path, PathValue } from \"./internal\";\nimport { createMemo, type Accessor } from \"solid-js\";\nimport {\n createContext,\n consume as _consume,\n provide as _provide,\n type ICustomElement,\n} from \"component-register\";\n\nimport { getValueFromPath } from \"./internal/index.js\";\nimport { formatValue, type Format } from \"../utils/index.js\";\n\ntype WalkableNode = Parameters<typeof _provide>[2];\n\nexport type { Path, PathValue };\n\nexport const makeFullPropertyPathContext = <RootData = any>() => {\n type FullPropertyPathContextType = ReturnType<\n typeof createFullPathPropertyContext\n >;\n\n type Options = {\n path: Accessor<Path<RootData>>;\n element: HTMLElement & ICustomElement;\n };\n function createFullPathPropertyContext(\n options: Options\n ): Accessor<Path<RootData>> {\n return options.path;\n }\n\n const Context = createContext(createFullPathPropertyContext);\n\n function provide({\n element,\n path,\n }: {\n element: WalkableNode;\n path: Accessor<Path<RootData>>;\n }): FullPropertyPathContextType {\n return _provide(Context, { path }, element);\n }\n\n function useFullPropertyPathContext(context: FullPropertyPathContextType) {\n return context;\n }\n\n function usePath(props: {\n element: HTMLElement & ICustomElement;\n path?: Accessor<Path<RootData>>;\n }): Accessor<Path<RootData>> {\n const context = _consume(Context, props.element);\n const basePath = useFullPropertyPathContext(context);\n return createMemo(() => {\n if (typeof basePath !== \"function\" && typeof props.path === \"function\") {\n return props.path();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path !== \"function\"\n ) {\n return basePath();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path === \"function\"\n ) {\n return `${basePath()}.${props.path()}`;\n }\n return \"\";\n }) as Accessor<Path<RootData>>;\n }\n\n type PathValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function usePathValue<P extends Path<RootData>>(\n options: PathValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n return createMemo(() => {\n const data = options.data();\n if (typeof options.path !== \"function\") return data;\n const path = options.path();\n if (!path) return data;\n const v = getValueFromPath(data, path as any);\n if (v === undefined || v === null) return null;\n return v;\n }) as Accessor<PathValue<RootData, P>>;\n }\n\n type FormmatedValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n format?: Format;\n element: HTMLElement & ICustomElement;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function useFormattedValue<P extends Path<RootData>>(\n options: FormmatedValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n const value = usePathValue({ path: options.path, data: options.data });\n\n const formattedValue = createMemo(() => {\n const v = value();\n if (v === null) return null;\n if (\n typeof v === \"string\" ||\n typeof v === \"number\" ||\n typeof v === \"boolean\"\n ) {\n return formatValue(options.format || \"\", v);\n }\n console.warn(\n options.element,\n `useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,\n v\n );\n return null;\n });\n\n return formattedValue as Accessor<PathValue<RootData, P>>;\n }\n\n return {\n provide,\n usePath,\n usePathValue,\n useFormattedValue,\n };\n};\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createFocusTrap as createFocusTrap$1 } from 'focus-trap';
|
|
2
|
-
import { createMemo, createEffect, on, createRoot,
|
|
3
|
-
import { compose, register, noShadowDOM } from 'component-register';
|
|
2
|
+
import { createMemo, onCleanup, createEffect, on, createRoot, createSignal } from 'solid-js';
|
|
3
|
+
import { compose, register, createContext, provide, consume, noShadowDOM } from 'component-register';
|
|
4
4
|
import { insert } from 'solid-js/web';
|
|
5
5
|
|
|
6
6
|
// src/focusTrap/index.ts
|
|
@@ -183,6 +183,15 @@ function customElement(tagName, props, Component = () => {
|
|
|
183
183
|
}, ...rest) {
|
|
184
184
|
return compose(register(tagName, props), withSolid, ...rest)(Component);
|
|
185
185
|
}
|
|
186
|
+
function isConstructable(fn) {
|
|
187
|
+
if (typeof fn !== "function") return false;
|
|
188
|
+
try {
|
|
189
|
+
Reflect.construct(String, [], fn);
|
|
190
|
+
return true;
|
|
191
|
+
} catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
186
195
|
function customShadowlessElement(tagName, props, Component = () => {
|
|
187
196
|
}, ...rest) {
|
|
188
197
|
return compose(
|
|
@@ -190,7 +199,16 @@ function customShadowlessElement(tagName, props, Component = () => {
|
|
|
190
199
|
withNoShadowDOM,
|
|
191
200
|
withSolid,
|
|
192
201
|
...rest
|
|
193
|
-
)(
|
|
202
|
+
)((...args) => {
|
|
203
|
+
onCleanup(() => {
|
|
204
|
+
const [_, { element }] = args;
|
|
205
|
+
element.dispatchEvent(new CustomEvent("bryt-designs:element-destroyed"));
|
|
206
|
+
});
|
|
207
|
+
if (isConstructable(Component)) {
|
|
208
|
+
return new Component(...args);
|
|
209
|
+
}
|
|
210
|
+
return Component(...args);
|
|
211
|
+
});
|
|
194
212
|
}
|
|
195
213
|
var correctElementType = (component) => {
|
|
196
214
|
return (props, options) => {
|
|
@@ -234,31 +252,42 @@ function invokeOnLoaded(fn, { signal }) {
|
|
|
234
252
|
return;
|
|
235
253
|
}
|
|
236
254
|
function createWithElementContext(context) {
|
|
237
|
-
return function(
|
|
255
|
+
return function(target, dependencies = () => null, cb) {
|
|
238
256
|
createEffect(
|
|
239
257
|
on(
|
|
240
258
|
() => {
|
|
241
|
-
const
|
|
259
|
+
const t = typeof target === "string" ? target : target();
|
|
242
260
|
return {
|
|
243
|
-
|
|
261
|
+
target: t,
|
|
244
262
|
dependencies: dependencies()
|
|
245
263
|
};
|
|
246
264
|
},
|
|
247
|
-
({
|
|
265
|
+
({ target: _target, dependencies: dependencies2 }) => {
|
|
248
266
|
const controller = new AbortController();
|
|
249
267
|
invokeOnLoaded(
|
|
250
268
|
() => {
|
|
251
|
-
let
|
|
269
|
+
let target2 = _target instanceof Element ? _target : null;
|
|
252
270
|
try {
|
|
253
|
-
|
|
271
|
+
if (typeof _target === "string")
|
|
272
|
+
target2 = document.querySelector(_target);
|
|
273
|
+
else if (typeof _target === "function") target2 = _target();
|
|
254
274
|
} catch (e) {
|
|
255
275
|
}
|
|
256
|
-
if (!
|
|
276
|
+
if (!target2 && typeof _target === "string")
|
|
257
277
|
return console.warn(`Target element not found!`, {
|
|
258
|
-
target:
|
|
278
|
+
target: _target
|
|
259
279
|
});
|
|
280
|
+
else if (!target2)
|
|
281
|
+
return console.warn(`Target element not found!`);
|
|
282
|
+
target2.addEventListener(
|
|
283
|
+
"bryt-designs:element-destroyed",
|
|
284
|
+
() => {
|
|
285
|
+
controller.abort("Context element destroyed");
|
|
286
|
+
},
|
|
287
|
+
{ once: true }
|
|
288
|
+
);
|
|
260
289
|
createRoot((dispose) => {
|
|
261
|
-
const c = getContextFromProvider(context,
|
|
290
|
+
const c = getContextFromProvider(context, target2);
|
|
262
291
|
const unsub = cb(c, dependencies2);
|
|
263
292
|
onCleanup(() => {
|
|
264
293
|
if (typeof unsub === "function") unsub();
|
|
@@ -271,7 +300,7 @@ function createWithElementContext(context) {
|
|
|
271
300
|
{ signal: controller.signal }
|
|
272
301
|
);
|
|
273
302
|
onCleanup(() => {
|
|
274
|
-
controller.abort();
|
|
303
|
+
controller.abort("Dependencies changed!");
|
|
275
304
|
});
|
|
276
305
|
}
|
|
277
306
|
)
|
|
@@ -279,6 +308,103 @@ function createWithElementContext(context) {
|
|
|
279
308
|
};
|
|
280
309
|
}
|
|
281
310
|
|
|
282
|
-
|
|
311
|
+
// src/utils/formatValue.ts
|
|
312
|
+
function formatValue(format, value) {
|
|
313
|
+
switch (format) {
|
|
314
|
+
case "currency":
|
|
315
|
+
if (typeof value === "number") return window.Shopify.formatMoney(value);
|
|
316
|
+
if (typeof value === "string")
|
|
317
|
+
return window.Shopify.formatMoney(parseFloat(value));
|
|
318
|
+
console.warn("formatValue: Unsupported value type for currency format.");
|
|
319
|
+
return window.Shopify.formatMoney(0);
|
|
320
|
+
case "number":
|
|
321
|
+
return Number(value);
|
|
322
|
+
case "boolean":
|
|
323
|
+
return Boolean(value);
|
|
324
|
+
case "invert_boolean":
|
|
325
|
+
return !Boolean(value);
|
|
326
|
+
default:
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/hooks/internal/getValueFromPath.ts
|
|
332
|
+
function getValueFromPath(obj, path) {
|
|
333
|
+
return path.split(".").reduce((acc, key) => {
|
|
334
|
+
if (acc === null || acc === void 0) return void 0;
|
|
335
|
+
const isArrayIndex = !isNaN(Number(key)) && key.trim() !== "";
|
|
336
|
+
if (Array.isArray(acc) && isArrayIndex) {
|
|
337
|
+
return acc[Number(key)];
|
|
338
|
+
}
|
|
339
|
+
return acc[key];
|
|
340
|
+
}, obj);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/hooks/makePathContextHooks.ts
|
|
344
|
+
var makeFullPropertyPathContext = () => {
|
|
345
|
+
function createFullPathPropertyContext(options) {
|
|
346
|
+
return options.path;
|
|
347
|
+
}
|
|
348
|
+
const Context = createContext(createFullPathPropertyContext);
|
|
349
|
+
function provide$1({
|
|
350
|
+
element,
|
|
351
|
+
path
|
|
352
|
+
}) {
|
|
353
|
+
return provide(Context, { path }, element);
|
|
354
|
+
}
|
|
355
|
+
function useFullPropertyPathContext(context) {
|
|
356
|
+
return context;
|
|
357
|
+
}
|
|
358
|
+
function usePath(props) {
|
|
359
|
+
const context = consume(Context, props.element);
|
|
360
|
+
const basePath = useFullPropertyPathContext(context);
|
|
361
|
+
return createMemo(() => {
|
|
362
|
+
if (typeof basePath !== "function" && typeof props.path === "function") {
|
|
363
|
+
return props.path();
|
|
364
|
+
} else if (typeof basePath === "function" && typeof props.path !== "function") {
|
|
365
|
+
return basePath();
|
|
366
|
+
} else if (typeof basePath === "function" && typeof props.path === "function") {
|
|
367
|
+
return `${basePath()}.${props.path()}`;
|
|
368
|
+
}
|
|
369
|
+
return "";
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function usePathValue(options) {
|
|
373
|
+
return createMemo(() => {
|
|
374
|
+
const data = options.data();
|
|
375
|
+
if (typeof options.path !== "function") return data;
|
|
376
|
+
const path = options.path();
|
|
377
|
+
if (!path) return data;
|
|
378
|
+
const v = getValueFromPath(data, path);
|
|
379
|
+
if (v === void 0 || v === null) return null;
|
|
380
|
+
return v;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function useFormattedValue(options) {
|
|
384
|
+
const value = usePathValue({ path: options.path, data: options.data });
|
|
385
|
+
const formattedValue = createMemo(() => {
|
|
386
|
+
const v = value();
|
|
387
|
+
if (v === null) return null;
|
|
388
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
389
|
+
return formatValue(options.format || "", v);
|
|
390
|
+
}
|
|
391
|
+
console.warn(
|
|
392
|
+
options.element,
|
|
393
|
+
`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,
|
|
394
|
+
v
|
|
395
|
+
);
|
|
396
|
+
return null;
|
|
397
|
+
});
|
|
398
|
+
return formattedValue;
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
provide: provide$1,
|
|
402
|
+
usePath,
|
|
403
|
+
usePathValue,
|
|
404
|
+
useFormattedValue
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
export { abortablePromise, awaitAllAnimations, checkLoaded, controlsToPromise, correctElementType, createFocusTrap, createWithElementContext, customElement, customShadowlessElement, formatValue, getContextFromProvider, getTransitionConfig, invokeOnLoaded, isCustomElement, makeFullPropertyPathContext, toHyphenated };
|
|
283
409
|
//# sourceMappingURL=index.js.map
|
|
284
410
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/focusTrap/index.ts","../../src/promise/abortablePromise.ts","../../src/animation/controlsToPromise.ts","../../src/animation/awaitAllAnimations.ts","../../src/animation/getTransitionConfig.ts","../../src/utils/toHyphenated.ts","../../src/utils/solid-element.ts","../../src/utils/isCustomElement.ts","../../src/utils/getContextFromProvider.ts","../../src/utils/checkLoaded.ts","../../src/utils/invokeOnLoaded.ts","../../src/utils/createWithElementContext.ts"],"names":["_createFocusTrap","selector","dependencies","createRoot"],"mappings":";;;;;;AAOA,IAAM,YAA8B,EAAC;AAE9B,IAAM,eAAkB,GAAA,CAC7B,OACA,EAAA,OAAA,KAEA,WAAW,MAAM;AACf,EAAM,MAAA,CAAA,GAAI,WAAe,IAAA;AAAA,IACvB;AAAA,GACF;AACA,EAAI,IAAA,CAAC,EAAE,SAAW,EAAA;AAChB,IAAA,CAAA,CAAE,SAAY,GAAA,SAAA;AAAA;AAEhB,EAAO,OAAAA,iBAAA,CAAiB,SAAS,CAAC,CAAA;AACpC,CAAC;;;ACrBI,SAAS,gBAA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,EAAmBD,aAAY,CAAA;AAEhD,gBAAA,SAAA,CAAU,MAAM;AACd,kBAAI,IAAA,OAAO,KAAU,KAAA,UAAA,EAAkB,KAAA,EAAA;AAAA,iBACxC,CAAA;AAED,gBAAW,UAAA,CAAA,MAAA,CAAO,gBAAiB,CAAA,OAAA,EAAS,OAAS,EAAA;AAAA,kBACnD,IAAM,EAAA;AAAA,iBACP,CAAA;AAAA,eACF,CAAA;AAAA,aACH;AAAA,YACA,EAAE,MAAQ,EAAA,UAAA,CAAW,MAAO;AAAA,WAC9B;AAGA,UAAA,SAAA,CAAU,MAAM;AACd,YAAA,UAAA,CAAW,KAAM,EAAA;AAAA,WAClB,CAAA;AAAA;AACH;AACF,KACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import {\n createFocusTrap as _createFocusTrap,\n type Options,\n type FocusTrap,\n} from \"focus-trap\";\nimport { createMemo, type Accessor } from \"solid-js\";\n\nconst trapStack: Array<FocusTrap> = [];\n\nexport const createFocusTrap = (\n element: HTMLElement,\n options?: Accessor<Options>,\n) =>\n createMemo(() => {\n const o = options?.() || {\n trapStack,\n };\n if (!o.trapStack) {\n o.trapStack = trapStack;\n }\n return _createFocusTrap(element, o);\n });\n","export function abortablePromise(promise: Promise<any>, signal: AbortSignal) {\n if (signal.aborted) {\n return new Promise((_, rej) => rej(signal.reason));\n }\n\n return new Promise(async (res, rej) => {\n signal.addEventListener(\n \"abort\",\n () => {\n rej(signal.reason);\n },\n { once: true },\n );\n promise.then(res);\n });\n}\n","import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport async function controlsToPromise(\n controls: AnimationPlaybackControlsWithThen,\n) {\n return new Promise((resolve) => {\n controls.then(() => resolve(null));\n });\n}\n","import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport function awaitAllAnimations(\n promises: AnimationPlaybackControlsWithThen[],\n) {\n return new Promise((resolve, _) => {\n const results: any[] = [];\n let remaining = promises.length;\n if (remaining === 0) {\n resolve([]); // zero‐length edge case\n return;\n }\n\n function updateResults<T>(value: T, index: number) {\n results[index] = value;\n remaining -= 1;\n if (remaining === 0) {\n resolve(results);\n }\n }\n\n promises.forEach((p, i) => {\n try {\n if (p?.state === \"idle\") {\n updateResults(null, i);\n } else {\n p.then(() => {\n updateResults(null, i);\n });\n }\n } catch (e) {\n p.then(() => {\n updateResults(null, i);\n });\n }\n });\n });\n}\n","import type {\n Easing,\n Transition,\n AnimationGeneratorType,\n RepeatType,\n} from \"motion\";\n\nexport function getTransitionConfig(style: CSSStyleDeclaration) {\n const properties = {\n bounce: style.getPropertyValue(\"--motion--bounce\"),\n bounceDamping: style.getPropertyValue(\"--motion--bounce-damping\"),\n bounceStiffness: style.getPropertyValue(\"--motion--bounce-stiffness\"),\n duration: style.getPropertyValue(\"--motion--duration\"),\n damping: style.getPropertyValue(\"--motion--damping\"),\n delay: style.getPropertyValue(\"--motion--delay\"),\n ease: style.getPropertyValue(\"--motion--ease\"),\n elapsed: style.getPropertyValue(\"--motion--elapsed\"),\n mass: style.getPropertyValue(\"--motion--mass\"),\n max: style.getPropertyValue(\"--motion--max\"),\n min: style.getPropertyValue(\"--motion--min\"),\n power: style.getPropertyValue(\"--motion--power\"),\n repeat: style.getPropertyValue(\"--motion--repeat\"),\n repeatDelay: style.getPropertyValue(\"--motion--repeat-delay\"),\n repeatType: style.getPropertyValue(\"--motion--repeat-type\"),\n restDelta: style.getPropertyValue(\"--motion--rest-delta\"),\n restSpeed: style.getPropertyValue(\"--motion--rest-speed\"),\n startTime: style.getPropertyValue(\"--motion--start-time\"),\n timeConstant: style.getPropertyValue(\"--motion--time-constant\"),\n times: style.getPropertyValue(\"--motion--times\"),\n type: style.getPropertyValue(\"--motion--type\"),\n velocity: style.getPropertyValue(\"--motion--velocity\"),\n visualDuration: style.getPropertyValue(\"--motion--visual-duration\"),\n };\n return {\n bounce: properties.bounce ? parseFloat(properties.bounce) : undefined,\n bounceDamping: properties.bounceDamping\n ? parseFloat(properties.bounceDamping)\n : undefined,\n bounceStiffness: properties.bounceStiffness\n ? parseFloat(properties.bounceStiffness)\n : undefined,\n duration: properties.duration ? parseFloat(properties.duration) : undefined,\n damping: properties.damping ? parseFloat(properties.damping) : undefined,\n delay: properties.delay ? parseFloat(properties.delay) : undefined,\n ease: (properties.ease ? properties.ease : undefined) as Easing,\n elapsed: properties.elapsed ? parseFloat(properties.elapsed) : undefined,\n mass: properties.mass ? parseFloat(properties.mass) : undefined,\n max: properties.max ? parseFloat(properties.max) : undefined,\n min: properties.min ? parseFloat(properties.min) : undefined,\n power: properties.power ? parseFloat(properties.power) : undefined,\n repeat: properties.repeat ? parseInt(properties.repeat) : undefined,\n repeatDelay: properties.repeatDelay\n ? parseFloat(properties.repeatDelay)\n : undefined,\n repeatType: (properties.repeatType\n ? properties.repeatType\n : undefined) as RepeatType,\n restDelta: properties.restDelta\n ? parseFloat(properties.restDelta)\n : undefined,\n restSpeed: properties.restSpeed\n ? parseFloat(properties.restSpeed)\n : undefined,\n startTime: properties.startTime\n ? parseFloat(properties.startTime)\n : undefined,\n timeConstant: properties.timeConstant\n ? parseFloat(properties.timeConstant)\n : undefined,\n type: (properties.type\n ? properties.type\n : undefined) as AnimationGeneratorType,\n velocity: properties.velocity ? parseFloat(properties.velocity) : undefined,\n visualDuration: properties.visualDuration\n ? parseFloat(properties.visualDuration)\n : undefined,\n } satisfies Transition;\n}\n","export function toHyphenated(str: string): string {\n return str\n .replace(/([A-Z])/g, \"-$1\") // Insert hyphen before uppercase letters\n .toLowerCase(); // Convert the entire string to lowercase\n}\n","import {\n register,\n type ComponentType as mComponentType,\n type ICustomElement,\n type FunctionComponent,\n type ComponentOptions,\n noShadowDOM,\n compose,\n} from \"component-register\";\nimport { createRoot, createSignal } from \"solid-js\";\nimport { insert } from \"solid-js/web\";\n\nexport type ComponentType<T> = mComponentType<T>;\n\ntype CorrectComponentOptions = { element: HTMLElement & ICustomElement };\n\nexport type CorrectComponentType<T> = (\n props: T,\n options: CorrectComponentOptions,\n) => unknown;\n\nfunction createProps<T extends object>(raw: T) {\n const keys = Object.keys(raw) as (keyof T)[];\n const props = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (typeof key === \"undefined\") continue;\n const [get, set] = createSignal(Reflect.get(raw, key));\n Object.defineProperty(props, key, {\n get,\n set(v) {\n set(() => v);\n },\n });\n }\n return props as T;\n}\n\nfunction lookupContext(el: ICustomElement & { _$owner?: any }) {\n if (el.assignedSlot && el.assignedSlot._$owner)\n return el.assignedSlot._$owner;\n let next: Element & { _$owner?: any } = el.parentNode;\n while (\n next &&\n !next._$owner &&\n !(\n next.assignedSlot &&\n (next.assignedSlot as Element & { _$owner?: any })._$owner\n )\n )\n next = next.parentNode as Element;\n return next && next.assignedSlot\n ? (next.assignedSlot as Element & { _$owner?: any })._$owner\n : el._$owner;\n}\n\nfunction withSolid<T extends object>(\n ComponentType: ComponentType<T>,\n): ComponentType<T> {\n return (rawProps: T, options: ComponentOptions) => {\n const { element } = options as {\n element: ICustomElement & { _$owner?: any };\n };\n return createRoot((dispose: Function) => {\n const props = createProps<T>(rawProps);\n\n element.addPropertyChangedCallback(\n (key: string, val: any) => (props[key as keyof T] = val),\n );\n element.addReleaseCallback(() => {\n element.renderRoot.textContent = \"\";\n dispose();\n });\n\n const comp = (ComponentType as FunctionComponent<T>)(props as T, options);\n return insert(element.renderRoot, comp);\n }, lookupContext(element));\n };\n}\n\nfunction withNoShadowDOM<T extends object>(\n Component: ComponentType<T> = () => {},\n) {\n return (props: T, options: ComponentOptions) => {\n noShadowDOM();\n const comp = (Component as FunctionComponent<T>)(props, options);\n return comp;\n };\n}\n\nexport function customElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(register(tagName, props), withSolid, ...rest)(Component);\n}\n\nexport function customShadowlessElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(\n register(tagName, props),\n withNoShadowDOM,\n withSolid,\n ...rest,\n )(Component);\n}\n\nexport const correctElementType = <T>(\n component: CorrectComponentType<T>,\n): ComponentType<T> => {\n return (props: T, options) => {\n return component(props, options as CorrectComponentOptions);\n };\n};\n","import type { ICustomElement } from \"component-register\";\nexport function isCustomElement(\n element: any,\n): element is ICustomElement & HTMLElement {\n return Reflect.has(element, \"__initialized\");\n}\n","import type { createContext } from \"component-register\";\n\nexport function getContextFromProvider<T>(\n context: ReturnType<typeof createContext>,\n element: Element,\n) {\n const ctxSymbol = Object.getOwnPropertySymbols(element).find(\n (s) => s.description === \"element-context\",\n );\n if (!ctxSymbol) {\n throw new Error(\"No context provider found for the provided element\");\n }\n // @ts-ignore\n const contexts = element[ctxSymbol];\n return contexts[context.id] as T;\n}\n","export function checkLoaded() {\n return (\n document.readyState === \"complete\" ||\n //@ts-ignore\n document.readyState === \"loaded\" ||\n document.readyState === \"interactive\"\n );\n}\n","import { checkLoaded } from \"./checkLoaded.js\";\n\nexport function invokeOnLoaded(\n fn: () => void,\n { signal }: { signal?: AbortSignal },\n) {\n if (checkLoaded()) {\n const id = setTimeout(() => fn());\n signal?.addEventListener(\"abort\", () => clearTimeout(id), {\n once: true,\n });\n return;\n }\n window.addEventListener(\"DOMContentLoaded\", fn, { signal, once: true });\n return;\n}\n","import type { createContext } from \"component-register\";\nimport { getContextFromProvider } from \"./getContextFromProvider.js\";\nimport { invokeOnLoaded } from \"./invokeOnLoaded.js\";\nimport {\n type Accessor,\n createEffect,\n createRoot,\n on,\n onCleanup,\n} from \"solid-js\";\n\n/**\n * Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.\n * */\n\nexport function createWithElementContext<\n Context extends ReturnType<typeof createContext>,\n ContextState = null,\n>(context: Context) {\n return function <D extends any>(\n selector: string | Accessor<string>,\n dependencies: Accessor<D> = () => null as D,\n cb: (context: ContextState, dependencies: D) => void | (() => void),\n ) {\n createEffect(\n on(\n () => {\n const s: string =\n typeof selector === \"string\" ? selector : selector();\n return {\n selector: s,\n dependencies: dependencies(),\n };\n },\n ({ selector, dependencies }) => {\n const controller = new AbortController();\n invokeOnLoaded(\n () => {\n let target: Element | null = null;\n try {\n target = document.querySelector(selector);\n } catch (e) {\n e;\n }\n if (!target)\n return console.warn(`Target element not found!`, {\n target: selector,\n });\n\n createRoot((dispose) => {\n const c = getContextFromProvider(context, target);\n\n const unsub = cb(c as ContextState, dependencies);\n\n onCleanup(() => {\n if (typeof unsub === \"function\") unsub();\n });\n\n controller.signal.addEventListener(\"abort\", dispose, {\n once: true,\n });\n });\n },\n { signal: controller.signal },\n );\n\n // abort controller when dependencies change\n onCleanup(() => {\n controller.abort();\n });\n },\n ),\n );\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/focusTrap/index.ts","../../src/promise/abortablePromise.ts","../../src/animation/controlsToPromise.ts","../../src/animation/awaitAllAnimations.ts","../../src/animation/getTransitionConfig.ts","../../src/utils/toHyphenated.ts","../../src/utils/solid-element.ts","../../src/utils/isCustomElement.ts","../../src/utils/getContextFromProvider.ts","../../src/utils/checkLoaded.ts","../../src/utils/invokeOnLoaded.ts","../../src/utils/createWithElementContext.ts","../../src/utils/formatValue.ts","../../src/hooks/internal/getValueFromPath.ts","../../src/hooks/makePathContextHooks.ts"],"names":["_createFocusTrap","dependencies","target","createRoot","onCleanup","provide","_provide","_consume","createMemo"],"mappings":";;;;;;AAOA,IAAM,YAA8B,EAAC;AAE9B,IAAM,eAAkB,GAAA,CAC7B,OACA,EAAA,OAAA,KAEA,WAAW,MAAM;AACf,EAAM,MAAA,CAAA,GAAI,WAAe,IAAA;AAAA,IACvB;AAAA,GACF;AACA,EAAI,IAAA,CAAC,EAAE,SAAW,EAAA;AAChB,IAAA,CAAA,CAAE,SAAY,GAAA,SAAA;AAAA;AAEhB,EAAO,OAAAA,iBAAA,CAAiB,SAAS,CAAC,CAAA;AACpC,CAAC;;;ACrBI,SAAS,gBAAA,CAAi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AAA,cAAA;AAAA;AAGT,EAAO,OAAA;AAAA,aACLH,SAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import {\n createFocusTrap as _createFocusTrap,\n type Options,\n type FocusTrap,\n} from \"focus-trap\";\nimport { createMemo, type Accessor } from \"solid-js\";\n\nconst trapStack: Array<FocusTrap> = [];\n\nexport const createFocusTrap = (\n element: HTMLElement,\n options?: Accessor<Options>,\n) =>\n createMemo(() => {\n const o = options?.() || {\n trapStack,\n };\n if (!o.trapStack) {\n o.trapStack = trapStack;\n }\n return _createFocusTrap(element, o);\n });\n","export function abortablePromise(promise: Promise<any>, signal: AbortSignal) {\n if (signal.aborted) {\n return new Promise((_, rej) => rej(signal.reason));\n }\n\n return new Promise(async (res, rej) => {\n signal.addEventListener(\n \"abort\",\n () => {\n rej(signal.reason);\n },\n { once: true },\n );\n promise.then(res);\n });\n}\n","import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport async function controlsToPromise(\n controls: AnimationPlaybackControlsWithThen,\n) {\n return new Promise((resolve) => {\n controls.then(() => resolve(null));\n });\n}\n","import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport function awaitAllAnimations(\n promises: AnimationPlaybackControlsWithThen[],\n) {\n return new Promise((resolve, _) => {\n const results: any[] = [];\n let remaining = promises.length;\n if (remaining === 0) {\n resolve([]); // zero‐length edge case\n return;\n }\n\n function updateResults<T>(value: T, index: number) {\n results[index] = value;\n remaining -= 1;\n if (remaining === 0) {\n resolve(results);\n }\n }\n\n promises.forEach((p, i) => {\n try {\n if (p?.state === \"idle\") {\n updateResults(null, i);\n } else {\n p.then(() => {\n updateResults(null, i);\n });\n }\n } catch (e) {\n p.then(() => {\n updateResults(null, i);\n });\n }\n });\n });\n}\n","import type {\n Easing,\n Transition,\n AnimationGeneratorType,\n RepeatType,\n} from \"motion\";\n\nexport function getTransitionConfig(style: CSSStyleDeclaration) {\n const properties = {\n bounce: style.getPropertyValue(\"--motion--bounce\"),\n bounceDamping: style.getPropertyValue(\"--motion--bounce-damping\"),\n bounceStiffness: style.getPropertyValue(\"--motion--bounce-stiffness\"),\n duration: style.getPropertyValue(\"--motion--duration\"),\n damping: style.getPropertyValue(\"--motion--damping\"),\n delay: style.getPropertyValue(\"--motion--delay\"),\n ease: style.getPropertyValue(\"--motion--ease\"),\n elapsed: style.getPropertyValue(\"--motion--elapsed\"),\n mass: style.getPropertyValue(\"--motion--mass\"),\n max: style.getPropertyValue(\"--motion--max\"),\n min: style.getPropertyValue(\"--motion--min\"),\n power: style.getPropertyValue(\"--motion--power\"),\n repeat: style.getPropertyValue(\"--motion--repeat\"),\n repeatDelay: style.getPropertyValue(\"--motion--repeat-delay\"),\n repeatType: style.getPropertyValue(\"--motion--repeat-type\"),\n restDelta: style.getPropertyValue(\"--motion--rest-delta\"),\n restSpeed: style.getPropertyValue(\"--motion--rest-speed\"),\n startTime: style.getPropertyValue(\"--motion--start-time\"),\n timeConstant: style.getPropertyValue(\"--motion--time-constant\"),\n times: style.getPropertyValue(\"--motion--times\"),\n type: style.getPropertyValue(\"--motion--type\"),\n velocity: style.getPropertyValue(\"--motion--velocity\"),\n visualDuration: style.getPropertyValue(\"--motion--visual-duration\"),\n };\n return {\n bounce: properties.bounce ? parseFloat(properties.bounce) : undefined,\n bounceDamping: properties.bounceDamping\n ? parseFloat(properties.bounceDamping)\n : undefined,\n bounceStiffness: properties.bounceStiffness\n ? parseFloat(properties.bounceStiffness)\n : undefined,\n duration: properties.duration ? parseFloat(properties.duration) : undefined,\n damping: properties.damping ? parseFloat(properties.damping) : undefined,\n delay: properties.delay ? parseFloat(properties.delay) : undefined,\n ease: (properties.ease ? properties.ease : undefined) as Easing,\n elapsed: properties.elapsed ? parseFloat(properties.elapsed) : undefined,\n mass: properties.mass ? parseFloat(properties.mass) : undefined,\n max: properties.max ? parseFloat(properties.max) : undefined,\n min: properties.min ? parseFloat(properties.min) : undefined,\n power: properties.power ? parseFloat(properties.power) : undefined,\n repeat: properties.repeat ? parseInt(properties.repeat) : undefined,\n repeatDelay: properties.repeatDelay\n ? parseFloat(properties.repeatDelay)\n : undefined,\n repeatType: (properties.repeatType\n ? properties.repeatType\n : undefined) as RepeatType,\n restDelta: properties.restDelta\n ? parseFloat(properties.restDelta)\n : undefined,\n restSpeed: properties.restSpeed\n ? parseFloat(properties.restSpeed)\n : undefined,\n startTime: properties.startTime\n ? parseFloat(properties.startTime)\n : undefined,\n timeConstant: properties.timeConstant\n ? parseFloat(properties.timeConstant)\n : undefined,\n type: (properties.type\n ? properties.type\n : undefined) as AnimationGeneratorType,\n velocity: properties.velocity ? parseFloat(properties.velocity) : undefined,\n visualDuration: properties.visualDuration\n ? parseFloat(properties.visualDuration)\n : undefined,\n } satisfies Transition;\n}\n","export function toHyphenated(str: string): string {\n return str\n .replace(/([A-Z])/g, \"-$1\") // Insert hyphen before uppercase letters\n .toLowerCase(); // Convert the entire string to lowercase\n}\n","import {\n register,\n type ComponentType as mComponentType,\n type ICustomElement,\n type FunctionComponent,\n type ComponentOptions,\n noShadowDOM,\n compose,\n} from \"component-register\";\nimport { createRoot, createSignal, onCleanup } from \"solid-js\";\nimport { insert } from \"solid-js/web\";\n\nexport type ComponentType<T> = mComponentType<T>;\n\ntype CorrectComponentOptions = { element: HTMLElement & ICustomElement };\n\nexport type CorrectComponentType<T> = (\n props: T,\n options: CorrectComponentOptions,\n) => unknown;\n\nfunction createProps<T extends object>(raw: T) {\n const keys = Object.keys(raw) as (keyof T)[];\n const props = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (typeof key === \"undefined\") continue;\n const [get, set] = createSignal(Reflect.get(raw, key));\n Object.defineProperty(props, key, {\n get,\n set(v) {\n set(() => v);\n },\n });\n }\n return props as T;\n}\n\nfunction lookupContext(el: ICustomElement & { _$owner?: any }) {\n if (el.assignedSlot && el.assignedSlot._$owner)\n return el.assignedSlot._$owner;\n let next: Element & { _$owner?: any } = el.parentNode;\n while (\n next &&\n !next._$owner &&\n !(\n next.assignedSlot &&\n (next.assignedSlot as Element & { _$owner?: any })._$owner\n )\n )\n next = next.parentNode as Element;\n return next && next.assignedSlot\n ? (next.assignedSlot as Element & { _$owner?: any })._$owner\n : el._$owner;\n}\n\nfunction withSolid<T extends object>(\n ComponentType: ComponentType<T>,\n): ComponentType<T> {\n return (rawProps: T, options: ComponentOptions) => {\n const { element } = options as {\n element: ICustomElement & { _$owner?: any };\n };\n return createRoot((dispose: Function) => {\n const props = createProps<T>(rawProps);\n\n element.addPropertyChangedCallback(\n (key: string, val: any) => (props[key as keyof T] = val),\n );\n element.addReleaseCallback(() => {\n element.renderRoot.textContent = \"\";\n dispose();\n });\n\n const comp = (ComponentType as FunctionComponent<T>)(props as T, options);\n return insert(element.renderRoot, comp);\n }, lookupContext(element));\n };\n}\n\nfunction withNoShadowDOM<T extends object>(\n Component: ComponentType<T> = () => {},\n) {\n return (props: T, options: ComponentOptions) => {\n noShadowDOM();\n const comp = (Component as FunctionComponent<T>)(props, options);\n return comp;\n };\n}\n\nexport function customElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(register(tagName, props), withSolid, ...rest)(Component);\n}\n\nfunction isConstructable(fn: unknown): fn is new (...args: any[]) => any {\n if (typeof fn !== \"function\") return false;\n\n try {\n Reflect.construct(String, [], fn as Function);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function customShadowlessElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(\n register(tagName, props),\n withNoShadowDOM,\n withSolid,\n ...rest,\n )((...args) => {\n onCleanup(() => {\n const [_, { element }] = args;\n element.dispatchEvent(new CustomEvent(\"bryt-designs:element-destroyed\"));\n });\n if (isConstructable(Component)) {\n return new Component(...args);\n }\n return Component(...args);\n });\n}\n\nexport const correctElementType = <T>(\n component: CorrectComponentType<T>,\n): ComponentType<T> => {\n return (props: T, options) => {\n return component(props, options as CorrectComponentOptions);\n };\n};\n","import type { ICustomElement } from \"component-register\";\nexport function isCustomElement(\n element: any,\n): element is ICustomElement & HTMLElement {\n return Reflect.has(element, \"__initialized\");\n}\n","import type { createContext } from \"component-register\";\n\nexport function getContextFromProvider<T>(\n context: ReturnType<typeof createContext>,\n element: Element,\n) {\n const ctxSymbol = Object.getOwnPropertySymbols(element).find(\n (s) => s.description === \"element-context\",\n );\n if (!ctxSymbol) {\n throw new Error(\"No context provider found for the provided element\");\n }\n // @ts-ignore\n const contexts = element[ctxSymbol];\n return contexts[context.id] as T;\n}\n","export function checkLoaded() {\n return (\n document.readyState === \"complete\" ||\n //@ts-ignore\n document.readyState === \"loaded\" ||\n document.readyState === \"interactive\"\n );\n}\n","import { checkLoaded } from \"./checkLoaded.js\";\n\nexport function invokeOnLoaded(\n fn: () => void,\n { signal }: { signal?: AbortSignal },\n) {\n if (checkLoaded()) {\n const id = setTimeout(() => fn());\n signal?.addEventListener(\"abort\", () => clearTimeout(id), {\n once: true,\n });\n return;\n }\n window.addEventListener(\"DOMContentLoaded\", fn, { signal, once: true });\n return;\n}\n","import type { createContext } from \"component-register\";\nimport { getContextFromProvider } from \"./getContextFromProvider.js\";\nimport { invokeOnLoaded } from \"./invokeOnLoaded.js\";\nimport {\n type Accessor,\n createEffect,\n createRoot,\n on,\n onCleanup,\n} from \"solid-js\";\n\n/**\n * Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.\n * */\n\nexport function createWithElementContext<\n Context extends ReturnType<typeof createContext>,\n ContextState = null,\n>(context: Context) {\n return function <D extends any>(\n target: string | Accessor<string> | Accessor<() => Element>,\n dependencies: Accessor<D> = () => null as D,\n cb: (context: ContextState, dependencies: D) => void | (() => void),\n ) {\n createEffect(\n on(\n () => {\n const t = typeof target === \"string\" ? target : target();\n return {\n target: t,\n dependencies: dependencies(),\n };\n },\n ({ target: _target, dependencies }) => {\n const controller = new AbortController();\n invokeOnLoaded(\n () => {\n let target: Element | null =\n _target instanceof Element ? _target : null;\n try {\n if (typeof _target === \"string\")\n target = document.querySelector(_target);\n else if (typeof _target === \"function\") target = _target();\n } catch (e) {\n e;\n }\n if (!target && typeof _target === \"string\")\n return console.warn(`Target element not found!`, {\n target: _target,\n });\n else if (!target)\n return console.warn(`Target element not found!`);\n\n target.addEventListener(\n \"bryt-designs:element-destroyed\",\n () => {\n controller.abort(\"Context element destroyed\");\n },\n { once: true },\n );\n\n createRoot((dispose) => {\n const c = getContextFromProvider(context, target);\n\n const unsub = cb(c as ContextState, dependencies);\n\n onCleanup(() => {\n if (typeof unsub === \"function\") unsub();\n });\n\n controller.signal.addEventListener(\"abort\", dispose, {\n once: true,\n });\n });\n },\n { signal: controller.signal },\n );\n\n // abort controller when dependencies change\n onCleanup(() => {\n controller.abort(\"Dependencies changed!\");\n });\n },\n ),\n );\n };\n}\n","export type Format =\n | \"currency\"\n | \"number\"\n | \"boolean\"\n | \"invert_boolean\"\n | string;\n\nexport function formatValue(format: Format, value: unknown) {\n switch (format) {\n case \"currency\":\n if (typeof value === \"number\") return window.Shopify.formatMoney(value);\n if (typeof value === \"string\")\n return window.Shopify.formatMoney(parseFloat(value));\n console.warn(\"formatValue: Unsupported value type for currency format.\");\n return window.Shopify.formatMoney(0);\n case \"number\":\n return Number(value);\n case \"boolean\":\n return Boolean(value);\n case \"invert_boolean\":\n return !Boolean(value);\n default:\n return value as any;\n }\n}\n\ndeclare global {\n interface Window {\n Shopify: {\n formatMoney(value: number, currency?: string): string;\n };\n }\n}\n","export type Path<T> = T extends readonly (infer U)[]\n ? `${number}` | `${number}.${Path<U>}` // Allows indexing into readonly arrays\n : T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object | any[]\n ? `${K}` | `${K}.${Path<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\nexport type PathValue<\n T,\n P extends string,\n> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : Key extends `${number}`\n ? T extends readonly (infer U)[]\n ? PathValue<U, Rest>\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${number}`\n ? T extends readonly (infer U)[]\n ? U\n : undefined\n : undefined;\n\nexport function getValueFromPath<T, P extends Path<T>>(\n obj: T,\n path: P\n): PathValue<T, P> {\n return path.split(\".\").reduce<any>((acc, key) => {\n if (acc === null || acc === undefined) return undefined;\n\n const isArrayIndex = !isNaN(Number(key)) && key.trim() !== \"\";\n if (Array.isArray(acc) && isArrayIndex) {\n return acc[Number(key)];\n }\n\n return acc[key];\n }, obj) as PathValue<T, P>;\n}\n","import type { Path, PathValue } from \"./internal\";\nimport { createMemo, type Accessor } from \"solid-js\";\nimport {\n createContext,\n consume as _consume,\n provide as _provide,\n type ICustomElement,\n} from \"component-register\";\n\nimport { getValueFromPath } from \"./internal/index.js\";\nimport { formatValue, type Format } from \"../utils/index.js\";\n\ntype WalkableNode = Parameters<typeof _provide>[2];\n\nexport type { Path, PathValue };\n\nexport const makeFullPropertyPathContext = <RootData = any>() => {\n type FullPropertyPathContextType = ReturnType<\n typeof createFullPathPropertyContext\n >;\n\n type Options = {\n path: Accessor<Path<RootData>>;\n element: HTMLElement & ICustomElement;\n };\n function createFullPathPropertyContext(\n options: Options\n ): Accessor<Path<RootData>> {\n return options.path;\n }\n\n const Context = createContext(createFullPathPropertyContext);\n\n function provide({\n element,\n path,\n }: {\n element: WalkableNode;\n path: Accessor<Path<RootData>>;\n }): FullPropertyPathContextType {\n return _provide(Context, { path }, element);\n }\n\n function useFullPropertyPathContext(context: FullPropertyPathContextType) {\n return context;\n }\n\n function usePath(props: {\n element: HTMLElement & ICustomElement;\n path?: Accessor<Path<RootData>>;\n }): Accessor<Path<RootData>> {\n const context = _consume(Context, props.element);\n const basePath = useFullPropertyPathContext(context);\n return createMemo(() => {\n if (typeof basePath !== \"function\" && typeof props.path === \"function\") {\n return props.path();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path !== \"function\"\n ) {\n return basePath();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path === \"function\"\n ) {\n return `${basePath()}.${props.path()}`;\n }\n return \"\";\n }) as Accessor<Path<RootData>>;\n }\n\n type PathValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function usePathValue<P extends Path<RootData>>(\n options: PathValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n return createMemo(() => {\n const data = options.data();\n if (typeof options.path !== \"function\") return data;\n const path = options.path();\n if (!path) return data;\n const v = getValueFromPath(data, path as any);\n if (v === undefined || v === null) return null;\n return v;\n }) as Accessor<PathValue<RootData, P>>;\n }\n\n type FormmatedValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n format?: Format;\n element: HTMLElement & ICustomElement;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function useFormattedValue<P extends Path<RootData>>(\n options: FormmatedValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n const value = usePathValue({ path: options.path, data: options.data });\n\n const formattedValue = createMemo(() => {\n const v = value();\n if (v === null) return null;\n if (\n typeof v === \"string\" ||\n typeof v === \"number\" ||\n typeof v === \"boolean\"\n ) {\n return formatValue(options.format || \"\", v);\n }\n console.warn(\n options.element,\n `useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,\n v\n );\n return null;\n });\n\n return formattedValue as Accessor<PathValue<RootData, P>>;\n }\n\n return {\n provide,\n usePath,\n usePathValue,\n useFormattedValue,\n };\n};\n"]}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compose, register, noShadowDOM } from 'component-register';
|
|
2
|
-
import { createEffect, on, createRoot,
|
|
2
|
+
import { onCleanup, createEffect, on, createRoot, createSignal } from 'solid-js';
|
|
3
3
|
import { insert } from 'solid-js/web';
|
|
4
4
|
|
|
5
5
|
// src/utils/toHyphenated.ts
|
|
@@ -59,6 +59,15 @@ function customElement(tagName, props, Component = () => {
|
|
|
59
59
|
}, ...rest) {
|
|
60
60
|
return compose(register(tagName, props), withSolid, ...rest)(Component);
|
|
61
61
|
}
|
|
62
|
+
function isConstructable(fn) {
|
|
63
|
+
if (typeof fn !== "function") return false;
|
|
64
|
+
try {
|
|
65
|
+
Reflect.construct(String, [], fn);
|
|
66
|
+
return true;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
62
71
|
function customShadowlessElement(tagName, props, Component = () => {
|
|
63
72
|
}, ...rest) {
|
|
64
73
|
return compose(
|
|
@@ -66,7 +75,16 @@ function customShadowlessElement(tagName, props, Component = () => {
|
|
|
66
75
|
withNoShadowDOM,
|
|
67
76
|
withSolid,
|
|
68
77
|
...rest
|
|
69
|
-
)(
|
|
78
|
+
)((...args) => {
|
|
79
|
+
onCleanup(() => {
|
|
80
|
+
const [_, { element }] = args;
|
|
81
|
+
element.dispatchEvent(new CustomEvent("bryt-designs:element-destroyed"));
|
|
82
|
+
});
|
|
83
|
+
if (isConstructable(Component)) {
|
|
84
|
+
return new Component(...args);
|
|
85
|
+
}
|
|
86
|
+
return Component(...args);
|
|
87
|
+
});
|
|
70
88
|
}
|
|
71
89
|
var correctElementType = (component) => {
|
|
72
90
|
return (props, options) => {
|
|
@@ -110,31 +128,42 @@ function invokeOnLoaded(fn, { signal }) {
|
|
|
110
128
|
return;
|
|
111
129
|
}
|
|
112
130
|
function createWithElementContext(context) {
|
|
113
|
-
return function(
|
|
131
|
+
return function(target, dependencies = () => null, cb) {
|
|
114
132
|
createEffect(
|
|
115
133
|
on(
|
|
116
134
|
() => {
|
|
117
|
-
const
|
|
135
|
+
const t = typeof target === "string" ? target : target();
|
|
118
136
|
return {
|
|
119
|
-
|
|
137
|
+
target: t,
|
|
120
138
|
dependencies: dependencies()
|
|
121
139
|
};
|
|
122
140
|
},
|
|
123
|
-
({
|
|
141
|
+
({ target: _target, dependencies: dependencies2 }) => {
|
|
124
142
|
const controller = new AbortController();
|
|
125
143
|
invokeOnLoaded(
|
|
126
144
|
() => {
|
|
127
|
-
let
|
|
145
|
+
let target2 = _target instanceof Element ? _target : null;
|
|
128
146
|
try {
|
|
129
|
-
|
|
147
|
+
if (typeof _target === "string")
|
|
148
|
+
target2 = document.querySelector(_target);
|
|
149
|
+
else if (typeof _target === "function") target2 = _target();
|
|
130
150
|
} catch (e) {
|
|
131
151
|
}
|
|
132
|
-
if (!
|
|
152
|
+
if (!target2 && typeof _target === "string")
|
|
133
153
|
return console.warn(`Target element not found!`, {
|
|
134
|
-
target:
|
|
154
|
+
target: _target
|
|
135
155
|
});
|
|
156
|
+
else if (!target2)
|
|
157
|
+
return console.warn(`Target element not found!`);
|
|
158
|
+
target2.addEventListener(
|
|
159
|
+
"bryt-designs:element-destroyed",
|
|
160
|
+
() => {
|
|
161
|
+
controller.abort("Context element destroyed");
|
|
162
|
+
},
|
|
163
|
+
{ once: true }
|
|
164
|
+
);
|
|
136
165
|
createRoot((dispose) => {
|
|
137
|
-
const c = getContextFromProvider(context,
|
|
166
|
+
const c = getContextFromProvider(context, target2);
|
|
138
167
|
const unsub = cb(c, dependencies2);
|
|
139
168
|
onCleanup(() => {
|
|
140
169
|
if (typeof unsub === "function") unsub();
|
|
@@ -147,7 +176,7 @@ function createWithElementContext(context) {
|
|
|
147
176
|
{ signal: controller.signal }
|
|
148
177
|
);
|
|
149
178
|
onCleanup(() => {
|
|
150
|
-
controller.abort();
|
|
179
|
+
controller.abort("Dependencies changed!");
|
|
151
180
|
});
|
|
152
181
|
}
|
|
153
182
|
)
|
|
@@ -155,6 +184,26 @@ function createWithElementContext(context) {
|
|
|
155
184
|
};
|
|
156
185
|
}
|
|
157
186
|
|
|
158
|
-
|
|
187
|
+
// src/utils/formatValue.ts
|
|
188
|
+
function formatValue(format, value) {
|
|
189
|
+
switch (format) {
|
|
190
|
+
case "currency":
|
|
191
|
+
if (typeof value === "number") return window.Shopify.formatMoney(value);
|
|
192
|
+
if (typeof value === "string")
|
|
193
|
+
return window.Shopify.formatMoney(parseFloat(value));
|
|
194
|
+
console.warn("formatValue: Unsupported value type for currency format.");
|
|
195
|
+
return window.Shopify.formatMoney(0);
|
|
196
|
+
case "number":
|
|
197
|
+
return Number(value);
|
|
198
|
+
case "boolean":
|
|
199
|
+
return Boolean(value);
|
|
200
|
+
case "invert_boolean":
|
|
201
|
+
return !Boolean(value);
|
|
202
|
+
default:
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { checkLoaded, correctElementType, createWithElementContext, customElement, customShadowlessElement, formatValue, getContextFromProvider, invokeOnLoaded, isCustomElement, toHyphenated };
|
|
159
208
|
//# sourceMappingURL=index.js.map
|
|
160
209
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/toHyphenated.ts","../../../src/utils/solid-element.ts","../../../src/utils/isCustomElement.ts","../../../src/utils/getContextFromProvider.ts","../../../src/utils/checkLoaded.ts","../../../src/utils/invokeOnLoaded.ts","../../../src/utils/createWithElementContext.ts"],"names":["selector","dependencies","createRoot"],"mappings":";;;;;AAAO,SAAS,aAAa,GAAqB,EAAA;AAChD,EAAA,OAAO,GACJ,CAAA,OAAA,CAAQ,UAAY,EAAA,KAAK,EACzB,WAAY,EAAA;AACjB;ACiBA,SAAS,YAA8B,GAAQ,EAAA;AAC7C,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,IAAA,CAAK,GAAG,CAAA;AAC5B,EAAA,MAAM,QAAQ,EAAC;AACf,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,IAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAClB,IAAI,IAAA,OAAO,QAAQ,WAAa,EAAA;AAChC,IAAM,MAAA,CAAC,KAAK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AA;AAC9B,UAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AACvC,UAAA,cAAA;AAAA,YACE,MAAM;AACJ,cAAA,IAAI,MAAyB,GAAA,IAAA;AAC7B,cAAI,IAAA;AACF,gBAAS,MAAA,GAAA,QAAA,CAAS,cAAcD,SAAQ,CAAA;AAAA,uBACjC,CAAG,EAAA;AACV;AAEF,cAAA,IAAI,CAAC,MAAA;AACH,gBAAO,OAAA,OAAA,CAAQ,KAAK,CAA6B,yBAAA,CAAA,EAAA;AAAA,kBAC/C,MAAQA,EAAAA;AAAA,iBACT,CAAA;AAEH,cAAAE,UAAAA,CAAW,CAAC,OAAY,KAAA;AACtB,gBAAM,MAAA,CAAA,GAAI,sBAAuB,CAAA,OAAA,EAAS,MAAM,CAAA;AAEhD,gBAAM,MAAA,KAAA,GAAQ,EAAG,CAAA,CAAA,EAAmBD,aAAY,CAAA;AAEhD,gBAAA,SAAA,CAAU,MAAM;AACd,kBAAI,IAAA,OAAO,KAAU,KAAA,UAAA,EAAkB,KAAA,EAAA;AAAA,iBACxC,CAAA;AAED,gBAAW,UAAA,CAAA,MAAA,CAAO,gBAAiB,CAAA,OAAA,EAAS,OAAS,EAAA;AAAA,kBACnD,IAAM,EAAA;AAAA,iBACP,CAAA;AAAA,eACF,CAAA;AAAA,aACH;AAAA,YACA,EAAE,MAAQ,EAAA,UAAA,CAAW,MAAO;AAAA,WAC9B;AAGA,UAAA,SAAA,CAAU,MAAM;AACd,YAAA,UAAA,CAAW,KAAM,EAAA;AAAA,WAClB,CAAA;AAAA;AACH;AACF,KACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["export function toHyphenated(str: string): string {\n return str\n .replace(/([A-Z])/g, \"-$1\") // Insert hyphen before uppercase letters\n .toLowerCase(); // Convert the entire string to lowercase\n}\n","import {\n register,\n type ComponentType as mComponentType,\n type ICustomElement,\n type FunctionComponent,\n type ComponentOptions,\n noShadowDOM,\n compose,\n} from \"component-register\";\nimport { createRoot, createSignal } from \"solid-js\";\nimport { insert } from \"solid-js/web\";\n\nexport type ComponentType<T> = mComponentType<T>;\n\ntype CorrectComponentOptions = { element: HTMLElement & ICustomElement };\n\nexport type CorrectComponentType<T> = (\n props: T,\n options: CorrectComponentOptions,\n) => unknown;\n\nfunction createProps<T extends object>(raw: T) {\n const keys = Object.keys(raw) as (keyof T)[];\n const props = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (typeof key === \"undefined\") continue;\n const [get, set] = createSignal(Reflect.get(raw, key));\n Object.defineProperty(props, key, {\n get,\n set(v) {\n set(() => v);\n },\n });\n }\n return props as T;\n}\n\nfunction lookupContext(el: ICustomElement & { _$owner?: any }) {\n if (el.assignedSlot && el.assignedSlot._$owner)\n return el.assignedSlot._$owner;\n let next: Element & { _$owner?: any } = el.parentNode;\n while (\n next &&\n !next._$owner &&\n !(\n next.assignedSlot &&\n (next.assignedSlot as Element & { _$owner?: any })._$owner\n )\n )\n next = next.parentNode as Element;\n return next && next.assignedSlot\n ? (next.assignedSlot as Element & { _$owner?: any })._$owner\n : el._$owner;\n}\n\nfunction withSolid<T extends object>(\n ComponentType: ComponentType<T>,\n): ComponentType<T> {\n return (rawProps: T, options: ComponentOptions) => {\n const { element } = options as {\n element: ICustomElement & { _$owner?: any };\n };\n return createRoot((dispose: Function) => {\n const props = createProps<T>(rawProps);\n\n element.addPropertyChangedCallback(\n (key: string, val: any) => (props[key as keyof T] = val),\n );\n element.addReleaseCallback(() => {\n element.renderRoot.textContent = \"\";\n dispose();\n });\n\n const comp = (ComponentType as FunctionComponent<T>)(props as T, options);\n return insert(element.renderRoot, comp);\n }, lookupContext(element));\n };\n}\n\nfunction withNoShadowDOM<T extends object>(\n Component: ComponentType<T> = () => {},\n) {\n return (props: T, options: ComponentOptions) => {\n noShadowDOM();\n const comp = (Component as FunctionComponent<T>)(props, options);\n return comp;\n };\n}\n\nexport function customElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(register(tagName, props), withSolid, ...rest)(Component);\n}\n\nexport function customShadowlessElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(\n register(tagName, props),\n withNoShadowDOM,\n withSolid,\n ...rest,\n )(Component);\n}\n\nexport const correctElementType = <T>(\n component: CorrectComponentType<T>,\n): ComponentType<T> => {\n return (props: T, options) => {\n return component(props, options as CorrectComponentOptions);\n };\n};\n","import type { ICustomElement } from \"component-register\";\nexport function isCustomElement(\n element: any,\n): element is ICustomElement & HTMLElement {\n return Reflect.has(element, \"__initialized\");\n}\n","import type { createContext } from \"component-register\";\n\nexport function getContextFromProvider<T>(\n context: ReturnType<typeof createContext>,\n element: Element,\n) {\n const ctxSymbol = Object.getOwnPropertySymbols(element).find(\n (s) => s.description === \"element-context\",\n );\n if (!ctxSymbol) {\n throw new Error(\"No context provider found for the provided element\");\n }\n // @ts-ignore\n const contexts = element[ctxSymbol];\n return contexts[context.id] as T;\n}\n","export function checkLoaded() {\n return (\n document.readyState === \"complete\" ||\n //@ts-ignore\n document.readyState === \"loaded\" ||\n document.readyState === \"interactive\"\n );\n}\n","import { checkLoaded } from \"./checkLoaded.js\";\n\nexport function invokeOnLoaded(\n fn: () => void,\n { signal }: { signal?: AbortSignal },\n) {\n if (checkLoaded()) {\n const id = setTimeout(() => fn());\n signal?.addEventListener(\"abort\", () => clearTimeout(id), {\n once: true,\n });\n return;\n }\n window.addEventListener(\"DOMContentLoaded\", fn, { signal, once: true });\n return;\n}\n","import type { createContext } from \"component-register\";\nimport { getContextFromProvider } from \"./getContextFromProvider.js\";\nimport { invokeOnLoaded } from \"./invokeOnLoaded.js\";\nimport {\n type Accessor,\n createEffect,\n createRoot,\n on,\n onCleanup,\n} from \"solid-js\";\n\n/**\n * Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.\n * */\n\nexport function createWithElementContext<\n Context extends ReturnType<typeof createContext>,\n ContextState = null,\n>(context: Context) {\n return function <D extends any>(\n selector: string | Accessor<string>,\n dependencies: Accessor<D> = () => null as D,\n cb: (context: ContextState, dependencies: D) => void | (() => void),\n ) {\n createEffect(\n on(\n () => {\n const s: string =\n typeof selector === \"string\" ? selector : selector();\n return {\n selector: s,\n dependencies: dependencies(),\n };\n },\n ({ selector, dependencies }) => {\n const controller = new AbortController();\n invokeOnLoaded(\n () => {\n let target: Element | null = null;\n try {\n target = document.querySelector(selector);\n } catch (e) {\n e;\n }\n if (!target)\n return console.warn(`Target element not found!`, {\n target: selector,\n });\n\n createRoot((dispose) => {\n const c = getContextFromProvider(context, target);\n\n const unsub = cb(c as ContextState, dependencies);\n\n onCleanup(() => {\n if (typeof unsub === \"function\") unsub();\n });\n\n controller.signal.addEventListener(\"abort\", dispose, {\n once: true,\n });\n });\n },\n { signal: controller.signal },\n );\n\n // abort controller when dependencies change\n onCleanup(() => {\n controller.abort();\n });\n },\n ),\n );\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/toHyphenated.ts","../../../src/utils/solid-element.ts","../../../src/utils/isCustomElement.ts","../../../src/utils/getContextFromProvider.ts","../../../src/utils/checkLoaded.ts","../../../src/utils/invokeOnLoaded.ts","../../../src/utils/createWithElementContext.ts","../../../src/utils/formatValue.ts"],"names":["dependencies","target","createRoot","onCleanup"],"mappings":";;;;;AAAO,SAAS,aAAa,GAAqB,EAAA;AAChD,EAAA,OAAO,GACJ,CAAA,OAAA,CAAQ,UAAY,EAAA,KAAK,EACzB,WAAY,EAAA;AACjB;ACiBA,SAAS,YAA8B,GAAQ,EAAA;AAC7C,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,IAAA,CAAK,GAAG,CAAA;AAC5B,EAAA,MAAM,QAAQ,EAAC;AACf,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC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AAO,MAAO,CAAA,OAAA,CAAQ,WAAY,CAAA,UAAA,CAAW,KAAK,CAAC,CAAA;AACrD,MAAA,OAAA,CAAQ,KAAK,0DAA0D,CAAA;AACvE,MAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,WAAA,CAAY,CAAC,CAAA;AAAA,IACrC,KAAK,QAAA;AACH,MAAA,OAAO,OAAO,KAAK,CAAA;AAAA,IACrB,KAAK,SAAA;AACH,MAAA,OAAO,QAAQ,KAAK,CAAA;AAAA,IACtB,KAAK,gBAAA;AACH,MAAO,OAAA,CAAC,QAAQ,KAAK,CAAA;AAAA,IACvB;AACE,MAAO,OAAA,KAAA;AAAA;AAEb","file":"index.js","sourcesContent":["export function toHyphenated(str: string): string {\n return str\n .replace(/([A-Z])/g, \"-$1\") // Insert hyphen before uppercase letters\n .toLowerCase(); // Convert the entire string to lowercase\n}\n","import {\n register,\n type ComponentType as mComponentType,\n type ICustomElement,\n type FunctionComponent,\n type ComponentOptions,\n noShadowDOM,\n compose,\n} from \"component-register\";\nimport { createRoot, createSignal, onCleanup } from \"solid-js\";\nimport { insert } from \"solid-js/web\";\n\nexport type ComponentType<T> = mComponentType<T>;\n\ntype CorrectComponentOptions = { element: HTMLElement & ICustomElement };\n\nexport type CorrectComponentType<T> = (\n props: T,\n options: CorrectComponentOptions,\n) => unknown;\n\nfunction createProps<T extends object>(raw: T) {\n const keys = Object.keys(raw) as (keyof T)[];\n const props = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (typeof key === \"undefined\") continue;\n const [get, set] = createSignal(Reflect.get(raw, key));\n Object.defineProperty(props, key, {\n get,\n set(v) {\n set(() => v);\n },\n });\n }\n return props as T;\n}\n\nfunction lookupContext(el: ICustomElement & { _$owner?: any }) {\n if (el.assignedSlot && el.assignedSlot._$owner)\n return el.assignedSlot._$owner;\n let next: Element & { _$owner?: any } = el.parentNode;\n while (\n next &&\n !next._$owner &&\n !(\n next.assignedSlot &&\n (next.assignedSlot as Element & { _$owner?: any })._$owner\n )\n )\n next = next.parentNode as Element;\n return next && next.assignedSlot\n ? (next.assignedSlot as Element & { _$owner?: any })._$owner\n : el._$owner;\n}\n\nfunction withSolid<T extends object>(\n ComponentType: ComponentType<T>,\n): ComponentType<T> {\n return (rawProps: T, options: ComponentOptions) => {\n const { element } = options as {\n element: ICustomElement & { _$owner?: any };\n };\n return createRoot((dispose: Function) => {\n const props = createProps<T>(rawProps);\n\n element.addPropertyChangedCallback(\n (key: string, val: any) => (props[key as keyof T] = val),\n );\n element.addReleaseCallback(() => {\n element.renderRoot.textContent = \"\";\n dispose();\n });\n\n const comp = (ComponentType as FunctionComponent<T>)(props as T, options);\n return insert(element.renderRoot, comp);\n }, lookupContext(element));\n };\n}\n\nfunction withNoShadowDOM<T extends object>(\n Component: ComponentType<T> = () => {},\n) {\n return (props: T, options: ComponentOptions) => {\n noShadowDOM();\n const comp = (Component as FunctionComponent<T>)(props, options);\n return comp;\n };\n}\n\nexport function customElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(register(tagName, props), withSolid, ...rest)(Component);\n}\n\nfunction isConstructable(fn: unknown): fn is new (...args: any[]) => any {\n if (typeof fn !== \"function\") return false;\n\n try {\n Reflect.construct(String, [], fn as Function);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function customShadowlessElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(\n register(tagName, props),\n withNoShadowDOM,\n withSolid,\n ...rest,\n )((...args) => {\n onCleanup(() => {\n const [_, { element }] = args;\n element.dispatchEvent(new CustomEvent(\"bryt-designs:element-destroyed\"));\n });\n if (isConstructable(Component)) {\n return new Component(...args);\n }\n return Component(...args);\n });\n}\n\nexport const correctElementType = <T>(\n component: CorrectComponentType<T>,\n): ComponentType<T> => {\n return (props: T, options) => {\n return component(props, options as CorrectComponentOptions);\n };\n};\n","import type { ICustomElement } from \"component-register\";\nexport function isCustomElement(\n element: any,\n): element is ICustomElement & HTMLElement {\n return Reflect.has(element, \"__initialized\");\n}\n","import type { createContext } from \"component-register\";\n\nexport function getContextFromProvider<T>(\n context: ReturnType<typeof createContext>,\n element: Element,\n) {\n const ctxSymbol = Object.getOwnPropertySymbols(element).find(\n (s) => s.description === \"element-context\",\n );\n if (!ctxSymbol) {\n throw new Error(\"No context provider found for the provided element\");\n }\n // @ts-ignore\n const contexts = element[ctxSymbol];\n return contexts[context.id] as T;\n}\n","export function checkLoaded() {\n return (\n document.readyState === \"complete\" ||\n //@ts-ignore\n document.readyState === \"loaded\" ||\n document.readyState === \"interactive\"\n );\n}\n","import { checkLoaded } from \"./checkLoaded.js\";\n\nexport function invokeOnLoaded(\n fn: () => void,\n { signal }: { signal?: AbortSignal },\n) {\n if (checkLoaded()) {\n const id = setTimeout(() => fn());\n signal?.addEventListener(\"abort\", () => clearTimeout(id), {\n once: true,\n });\n return;\n }\n window.addEventListener(\"DOMContentLoaded\", fn, { signal, once: true });\n return;\n}\n","import type { createContext } from \"component-register\";\nimport { getContextFromProvider } from \"./getContextFromProvider.js\";\nimport { invokeOnLoaded } from \"./invokeOnLoaded.js\";\nimport {\n type Accessor,\n createEffect,\n createRoot,\n on,\n onCleanup,\n} from \"solid-js\";\n\n/**\n * Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.\n * */\n\nexport function createWithElementContext<\n Context extends ReturnType<typeof createContext>,\n ContextState = null,\n>(context: Context) {\n return function <D extends any>(\n target: string | Accessor<string> | Accessor<() => Element>,\n dependencies: Accessor<D> = () => null as D,\n cb: (context: ContextState, dependencies: D) => void | (() => void),\n ) {\n createEffect(\n on(\n () => {\n const t = typeof target === \"string\" ? target : target();\n return {\n target: t,\n dependencies: dependencies(),\n };\n },\n ({ target: _target, dependencies }) => {\n const controller = new AbortController();\n invokeOnLoaded(\n () => {\n let target: Element | null =\n _target instanceof Element ? _target : null;\n try {\n if (typeof _target === \"string\")\n target = document.querySelector(_target);\n else if (typeof _target === \"function\") target = _target();\n } catch (e) {\n e;\n }\n if (!target && typeof _target === \"string\")\n return console.warn(`Target element not found!`, {\n target: _target,\n });\n else if (!target)\n return console.warn(`Target element not found!`);\n\n target.addEventListener(\n \"bryt-designs:element-destroyed\",\n () => {\n controller.abort(\"Context element destroyed\");\n },\n { once: true },\n );\n\n createRoot((dispose) => {\n const c = getContextFromProvider(context, target);\n\n const unsub = cb(c as ContextState, dependencies);\n\n onCleanup(() => {\n if (typeof unsub === \"function\") unsub();\n });\n\n controller.signal.addEventListener(\"abort\", dispose, {\n once: true,\n });\n });\n },\n { signal: controller.signal },\n );\n\n // abort controller when dependencies change\n onCleanup(() => {\n controller.abort(\"Dependencies changed!\");\n });\n },\n ),\n );\n };\n}\n","export type Format =\n | \"currency\"\n | \"number\"\n | \"boolean\"\n | \"invert_boolean\"\n | string;\n\nexport function formatValue(format: Format, value: unknown) {\n switch (format) {\n case \"currency\":\n if (typeof value === \"number\") return window.Shopify.formatMoney(value);\n if (typeof value === \"string\")\n return window.Shopify.formatMoney(parseFloat(value));\n console.warn(\"formatValue: Unsupported value type for currency format.\");\n return window.Shopify.formatMoney(0);\n case \"number\":\n return Number(value);\n case \"boolean\":\n return Boolean(value);\n case \"invert_boolean\":\n return !Boolean(value);\n default:\n return value as any;\n }\n}\n\ndeclare global {\n interface Window {\n Shopify: {\n formatMoney(value: number, currency?: string): string;\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ICustomElement, provide as _provide } from 'component-register';
|
|
4
|
+
import { Accessor } from 'solid-js';
|
|
5
|
+
|
|
6
|
+
export type Path<T> = T extends readonly (infer U)[] ? `${number}` | `${number}.${Path<U>}` : T extends object ? {
|
|
7
|
+
[K in keyof T & (string | number)]: T[K] extends object | any[] ? `${K}` | `${K}.${Path<T[K]>}` : `${K}`;
|
|
8
|
+
}[keyof T & (string | number)] : never;
|
|
9
|
+
export type PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? PathValue<T[Key], Rest> : Key extends `${number}` ? T extends readonly (infer U)[] ? PathValue<U, Rest> : undefined : undefined : P extends keyof T ? T[P] : P extends `${number}` ? T extends readonly (infer U)[] ? U : undefined : undefined;
|
|
10
|
+
export type Format = "currency" | "number" | "boolean" | "invert_boolean" | string;
|
|
11
|
+
export type WalkableNode = Parameters<typeof _provide>[2];
|
|
12
|
+
export declare const makeFullPropertyPathContext: <RootData = any>() => {
|
|
13
|
+
provide: ({ element, path, }: {
|
|
14
|
+
element: WalkableNode;
|
|
15
|
+
path: Accessor<Path<RootData>>;
|
|
16
|
+
}) => Accessor<Path<RootData>>;
|
|
17
|
+
usePath: (props: {
|
|
18
|
+
element: HTMLElement & ICustomElement;
|
|
19
|
+
path?: Accessor<Path<RootData>>;
|
|
20
|
+
}) => Accessor<Path<RootData>>;
|
|
21
|
+
usePathValue: <P extends Path<RootData>>(options: {
|
|
22
|
+
path: Accessor<P>;
|
|
23
|
+
data: Accessor<PathValue<RootData, P>>;
|
|
24
|
+
}) => Accessor<PathValue<RootData, P>>;
|
|
25
|
+
useFormattedValue: <P extends Path<RootData>>(options: {
|
|
26
|
+
path: Accessor<P>;
|
|
27
|
+
format?: Format;
|
|
28
|
+
element: HTMLElement & ICustomElement;
|
|
29
|
+
data: Accessor<PathValue<RootData, P>>;
|
|
30
|
+
}) => Accessor<PathValue<RootData, P>>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function getValueFromPath(obj, path) {
|
|
2
|
+
return path.split(".").reduce((acc, key) => {
|
|
3
|
+
if (acc === null || acc === void 0) return void 0;
|
|
4
|
+
const isArrayIndex = !isNaN(Number(key)) && key.trim() !== "";
|
|
5
|
+
if (Array.isArray(acc) && isArrayIndex) {
|
|
6
|
+
return acc[Number(key)];
|
|
7
|
+
}
|
|
8
|
+
return acc[key];
|
|
9
|
+
}, obj);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { getValueFromPath };
|
|
13
|
+
//# sourceMappingURL=getValueFromPath.js.map
|
|
14
|
+
//# sourceMappingURL=getValueFromPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/internal/getValueFromPath.ts"],"names":[],"mappings":"AA6BO,SAAS,gBAAA,CACd,KACA,IACiB,EAAA;AACjB,EAAA,OAAO,KAAK,KAAM,CAAA,GAAG,EAAE,MAAY,CAAA,CAAC,KAAK,GAAQ,KAAA;AAC/C,IAAA,IAAI,GAAQ,KAAA,IAAA,IAAQ,GAAQ,KAAA,MAAA,EAAkB,OAAA,MAAA;AAE9C,IAAM,MAAA,YAAA,GAAe,CAAC,KAAM,CAAA,MAAA,CAAO,GAAG,CAAC,CAAA,IAAK,GAAI,CAAA,IAAA,EAAW,KAAA,EAAA;AAC3D,IAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA,IAAK,YAAc,EAAA;AACtC,MAAO,OAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAC,CAAA;AAAA;AAGxB,IAAA,OAAO,IAAI,GAAG,CAAA;AAAA,KACb,GAAG,CAAA;AACR","file":"getValueFromPath.js","sourcesContent":["export type Path<T> = T extends readonly (infer U)[]\n ? `${number}` | `${number}.${Path<U>}` // Allows indexing into readonly arrays\n : T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object | any[]\n ? `${K}` | `${K}.${Path<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\nexport type PathValue<\n T,\n P extends string,\n> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : Key extends `${number}`\n ? T extends readonly (infer U)[]\n ? PathValue<U, Rest>\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${number}`\n ? T extends readonly (infer U)[]\n ? U\n : undefined\n : undefined;\n\nexport function getValueFromPath<T, P extends Path<T>>(\n obj: T,\n path: P\n): PathValue<T, P> {\n return path.split(\".\").reduce<any>((acc, key) => {\n if (acc === null || acc === undefined) return undefined;\n\n const isArrayIndex = !isNaN(Number(key)) && key.trim() !== \"\";\n if (Array.isArray(acc) && isArrayIndex) {\n return acc[Number(key)];\n }\n\n return acc[key];\n }, obj) as PathValue<T, P>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createMemo } from 'solid-js';
|
|
2
|
+
import { createContext, provide, consume } from 'component-register';
|
|
3
|
+
import { getValueFromPath } from './internal/index.js';
|
|
4
|
+
import { formatValue } from '../utils/index.js';
|
|
5
|
+
|
|
6
|
+
const makeFullPropertyPathContext = () => {
|
|
7
|
+
function createFullPathPropertyContext(options) {
|
|
8
|
+
return options.path;
|
|
9
|
+
}
|
|
10
|
+
const Context = createContext(createFullPathPropertyContext);
|
|
11
|
+
function provide$1({
|
|
12
|
+
element,
|
|
13
|
+
path
|
|
14
|
+
}) {
|
|
15
|
+
return provide(Context, { path }, element);
|
|
16
|
+
}
|
|
17
|
+
function useFullPropertyPathContext(context) {
|
|
18
|
+
return context;
|
|
19
|
+
}
|
|
20
|
+
function usePath(props) {
|
|
21
|
+
const context = consume(Context, props.element);
|
|
22
|
+
const basePath = useFullPropertyPathContext(context);
|
|
23
|
+
return createMemo(() => {
|
|
24
|
+
if (typeof basePath !== "function" && typeof props.path === "function") {
|
|
25
|
+
return props.path();
|
|
26
|
+
} else if (typeof basePath === "function" && typeof props.path !== "function") {
|
|
27
|
+
return basePath();
|
|
28
|
+
} else if (typeof basePath === "function" && typeof props.path === "function") {
|
|
29
|
+
return `${basePath()}.${props.path()}`;
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function usePathValue(options) {
|
|
35
|
+
return createMemo(() => {
|
|
36
|
+
const data = options.data();
|
|
37
|
+
if (typeof options.path !== "function") return data;
|
|
38
|
+
const path = options.path();
|
|
39
|
+
if (!path) return data;
|
|
40
|
+
const v = getValueFromPath(data, path);
|
|
41
|
+
if (v === void 0 || v === null) return null;
|
|
42
|
+
return v;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function useFormattedValue(options) {
|
|
46
|
+
const value = usePathValue({ path: options.path, data: options.data });
|
|
47
|
+
const formattedValue = createMemo(() => {
|
|
48
|
+
const v = value();
|
|
49
|
+
if (v === null) return null;
|
|
50
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
51
|
+
return formatValue(options.format || "", v);
|
|
52
|
+
}
|
|
53
|
+
console.warn(
|
|
54
|
+
options.element,
|
|
55
|
+
`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,
|
|
56
|
+
v
|
|
57
|
+
);
|
|
58
|
+
return null;
|
|
59
|
+
});
|
|
60
|
+
return formattedValue;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
provide: provide$1,
|
|
64
|
+
usePath,
|
|
65
|
+
usePathValue,
|
|
66
|
+
useFormattedValue
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { makeFullPropertyPathContext };
|
|
71
|
+
//# sourceMappingURL=makePathContextHooks.js.map
|
|
72
|
+
//# sourceMappingURL=makePathContextHooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/makePathContextHooks.ts"],"names":["provide","_provide","_consume"],"mappings":";;;;;AAgBO,MAAM,8BAA8B,MAAsB;AAS/D,EAAA,SAAS,8BACP,OAC0B,EAAA;AA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OAAA,IAAA;AAClB,MAAM,MAAA,CAAA,GAAI,gBAAiB,CAAA,IAAA,EAAM,IAAW,CAAA;AAC5C,MAAA,IAAI,CAAM,KAAA,MAAA,IAAa,CAAM,KAAA,IAAA,EAAa,OAAA,IAAA;AAC1C,MAAO,OAAA,CAAA;AAAA,KACR,CAAA;AAAA;AAUH,EAAA,SAAS,kBACP,OACkC,EAAA;AAClC,IAAM,MAAA,KAAA,GAAQ,aAAa,EAAE,IAAA,EAAM,QAAQ,IAAM,EAAA,IAAA,EAAM,OAAQ,CAAA,IAAA,EAAM,CAAA;AAErE,IAAM,MAAA,cAAA,GAAiB,WAAW,MAAM;AACtC,MAAA,MAAM,IAAI,KAAM,EAAA;AAChB,MAAI,IAAA,CAAA,KAAM,MAAa,OAAA,IAAA;AACvB,MACE,IAAA,OAAO,MAAM,QACb,IAAA,OAAO,MAAM,QACb,IAAA,OAAO,MAAM,SACb,EAAA;AACA,QAAA,OAAO,WAAY,CAAA,OAAA,CAAQ,MAAU,IAAA,EAAA,EAAI,CAAC,CAAA;AAAA;AAE5C,MAAQ,OAAA,CAAA,IAAA;AAAA,QACN,OAAQ,CAAA,OAAA;AAAA,QACR,CAAA,0FAAA,EAA6F,OAAO,CAAC,CAAA,CAAA,CAAA;AAAA,QACrG;AAAA,OACF;AACA,MAAO,OAAA,IAAA;AAAA,KACR,CAAA;AAED,IAAO,OAAA,cAAA;AAAA;AAGT,EAAO,OAAA;AAAA,aACLF,SAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"makePathContextHooks.js","sourcesContent":["import type { Path, PathValue } from \"./internal\";\nimport { createMemo, type Accessor } from \"solid-js\";\nimport {\n createContext,\n consume as _consume,\n provide as _provide,\n type ICustomElement,\n} from \"component-register\";\n\nimport { getValueFromPath } from \"./internal/index.js\";\nimport { formatValue, type Format } from \"../utils/index.js\";\n\ntype WalkableNode = Parameters<typeof _provide>[2];\n\nexport type { Path, PathValue };\n\nexport const makeFullPropertyPathContext = <RootData = any>() => {\n type FullPropertyPathContextType = ReturnType<\n typeof createFullPathPropertyContext\n >;\n\n type Options = {\n path: Accessor<Path<RootData>>;\n element: HTMLElement & ICustomElement;\n };\n function createFullPathPropertyContext(\n options: Options\n ): Accessor<Path<RootData>> {\n return options.path;\n }\n\n const Context = createContext(createFullPathPropertyContext);\n\n function provide({\n element,\n path,\n }: {\n element: WalkableNode;\n path: Accessor<Path<RootData>>;\n }): FullPropertyPathContextType {\n return _provide(Context, { path }, element);\n }\n\n function useFullPropertyPathContext(context: FullPropertyPathContextType) {\n return context;\n }\n\n function usePath(props: {\n element: HTMLElement & ICustomElement;\n path?: Accessor<Path<RootData>>;\n }): Accessor<Path<RootData>> {\n const context = _consume(Context, props.element);\n const basePath = useFullPropertyPathContext(context);\n return createMemo(() => {\n if (typeof basePath !== \"function\" && typeof props.path === \"function\") {\n return props.path();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path !== \"function\"\n ) {\n return basePath();\n } else if (\n typeof basePath === \"function\" &&\n typeof props.path === \"function\"\n ) {\n return `${basePath()}.${props.path()}`;\n }\n return \"\";\n }) as Accessor<Path<RootData>>;\n }\n\n type PathValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function usePathValue<P extends Path<RootData>>(\n options: PathValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n return createMemo(() => {\n const data = options.data();\n if (typeof options.path !== \"function\") return data;\n const path = options.path();\n if (!path) return data;\n const v = getValueFromPath(data, path as any);\n if (v === undefined || v === null) return null;\n return v;\n }) as Accessor<PathValue<RootData, P>>;\n }\n\n type FormmatedValueOptions<P extends Path<RootData>> = {\n path: Accessor<P>;\n format?: Format;\n element: HTMLElement & ICustomElement;\n data: Accessor<PathValue<RootData, P>>;\n };\n\n function useFormattedValue<P extends Path<RootData>>(\n options: FormmatedValueOptions<P>\n ): Accessor<PathValue<RootData, P>> {\n const value = usePathValue({ path: options.path, data: options.data });\n\n const formattedValue = createMemo(() => {\n const v = value();\n if (v === null) return null;\n if (\n typeof v === \"string\" ||\n typeof v === \"number\" ||\n typeof v === \"boolean\"\n ) {\n return formatValue(options.format || \"\", v);\n }\n console.warn(\n options.element,\n `useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,\n v\n );\n return null;\n });\n\n return formattedValue as Accessor<PathValue<RootData, P>>;\n }\n\n return {\n provide,\n usePath,\n usePathValue,\n useFormattedValue,\n };\n};\n"]}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { ComponentType as mComponentType, ICustomElement, createContext } from 'component-register';
|
|
3
|
+
import { ComponentType as mComponentType, ICustomElement, createContext, provide as _provide } from 'component-register';
|
|
4
4
|
import { FocusTrap, Options } from 'focus-trap';
|
|
5
5
|
import { AnimationGeneratorType, AnimationPlaybackControlsWithThen, Easing, RepeatType } from 'motion';
|
|
6
6
|
import { Accessor } from 'solid-js';
|
|
@@ -51,6 +51,33 @@ export declare function invokeOnLoaded(fn: () => void, { signal }: {
|
|
|
51
51
|
/**
|
|
52
52
|
* Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.
|
|
53
53
|
* */
|
|
54
|
-
export declare function createWithElementContext<Context extends ReturnType<typeof createContext>, ContextState = null>(context: Context): <D extends any>(
|
|
54
|
+
export declare function createWithElementContext<Context extends ReturnType<typeof createContext>, ContextState = null>(context: Context): <D extends any>(target: string | Accessor<string> | Accessor<() => Element>, dependencies: Accessor<D> | undefined, cb: (context: ContextState, dependencies: D) => void | (() => void)) => void;
|
|
55
|
+
export type Format = "currency" | "number" | "boolean" | "invert_boolean" | string;
|
|
56
|
+
export declare function formatValue(format: Format, value: unknown): any;
|
|
57
|
+
export type Path<T> = T extends readonly (infer U)[] ? `${number}` | `${number}.${Path<U>}` : T extends object ? {
|
|
58
|
+
[K in keyof T & (string | number)]: T[K] extends object | any[] ? `${K}` | `${K}.${Path<T[K]>}` : `${K}`;
|
|
59
|
+
}[keyof T & (string | number)] : never;
|
|
60
|
+
export type PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? PathValue<T[Key], Rest> : Key extends `${number}` ? T extends readonly (infer U)[] ? PathValue<U, Rest> : undefined : undefined : P extends keyof T ? T[P] : P extends `${number}` ? T extends readonly (infer U)[] ? U : undefined : undefined;
|
|
61
|
+
export type WalkableNode = Parameters<typeof _provide>[2];
|
|
62
|
+
export declare const makeFullPropertyPathContext: <RootData = any>() => {
|
|
63
|
+
provide: ({ element, path, }: {
|
|
64
|
+
element: WalkableNode;
|
|
65
|
+
path: Accessor<Path<RootData>>;
|
|
66
|
+
}) => Accessor<Path<RootData>>;
|
|
67
|
+
usePath: (props: {
|
|
68
|
+
element: HTMLElement & ICustomElement;
|
|
69
|
+
path?: Accessor<Path<RootData>>;
|
|
70
|
+
}) => Accessor<Path<RootData>>;
|
|
71
|
+
usePathValue: <P extends Path<RootData>>(options: {
|
|
72
|
+
path: Accessor<P>;
|
|
73
|
+
data: Accessor<PathValue<RootData, P>>;
|
|
74
|
+
}) => Accessor<PathValue<RootData, P>>;
|
|
75
|
+
useFormattedValue: <P extends Path<RootData>>(options: {
|
|
76
|
+
path: Accessor<P>;
|
|
77
|
+
format?: Format;
|
|
78
|
+
element: HTMLElement & ICustomElement;
|
|
79
|
+
data: Accessor<PathValue<RootData, P>>;
|
|
80
|
+
}) => Accessor<PathValue<RootData, P>>;
|
|
81
|
+
};
|
|
55
82
|
|
|
56
83
|
export {};
|
package/dist/main/index.js
CHANGED
|
@@ -3,31 +3,42 @@ import { invokeOnLoaded } from './invokeOnLoaded.js';
|
|
|
3
3
|
import { createEffect, on, createRoot, onCleanup } from 'solid-js';
|
|
4
4
|
|
|
5
5
|
function createWithElementContext(context) {
|
|
6
|
-
return function(
|
|
6
|
+
return function(target, dependencies = () => null, cb) {
|
|
7
7
|
createEffect(
|
|
8
8
|
on(
|
|
9
9
|
() => {
|
|
10
|
-
const
|
|
10
|
+
const t = typeof target === "string" ? target : target();
|
|
11
11
|
return {
|
|
12
|
-
|
|
12
|
+
target: t,
|
|
13
13
|
dependencies: dependencies()
|
|
14
14
|
};
|
|
15
15
|
},
|
|
16
|
-
({
|
|
16
|
+
({ target: _target, dependencies: dependencies2 }) => {
|
|
17
17
|
const controller = new AbortController();
|
|
18
18
|
invokeOnLoaded(
|
|
19
19
|
() => {
|
|
20
|
-
let
|
|
20
|
+
let target2 = _target instanceof Element ? _target : null;
|
|
21
21
|
try {
|
|
22
|
-
|
|
22
|
+
if (typeof _target === "string")
|
|
23
|
+
target2 = document.querySelector(_target);
|
|
24
|
+
else if (typeof _target === "function") target2 = _target();
|
|
23
25
|
} catch (e) {
|
|
24
26
|
}
|
|
25
|
-
if (!
|
|
27
|
+
if (!target2 && typeof _target === "string")
|
|
26
28
|
return console.warn(`Target element not found!`, {
|
|
27
|
-
target:
|
|
29
|
+
target: _target
|
|
28
30
|
});
|
|
31
|
+
else if (!target2)
|
|
32
|
+
return console.warn(`Target element not found!`);
|
|
33
|
+
target2.addEventListener(
|
|
34
|
+
"bryt-designs:element-destroyed",
|
|
35
|
+
() => {
|
|
36
|
+
controller.abort("Context element destroyed");
|
|
37
|
+
},
|
|
38
|
+
{ once: true }
|
|
39
|
+
);
|
|
29
40
|
createRoot((dispose) => {
|
|
30
|
-
const c = getContextFromProvider(context,
|
|
41
|
+
const c = getContextFromProvider(context, target2);
|
|
31
42
|
const unsub = cb(c, dependencies2);
|
|
32
43
|
onCleanup(() => {
|
|
33
44
|
if (typeof unsub === "function") unsub();
|
|
@@ -40,7 +51,7 @@ function createWithElementContext(context) {
|
|
|
40
51
|
{ signal: controller.signal }
|
|
41
52
|
);
|
|
42
53
|
onCleanup(() => {
|
|
43
|
-
controller.abort();
|
|
54
|
+
controller.abort("Dependencies changed!");
|
|
44
55
|
});
|
|
45
56
|
}
|
|
46
57
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/createWithElementContext.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/createWithElementContext.ts"],"names":["dependencies","target"],"mappings":";;;;AAeO,SAAS,yBAGd,OAAkB,EAAA;AAClB,EAAA,OAAO,SACL,MAAA,EACA,YAA4B,GAAA,MAAM,MAClC,EACA,EAAA;AACA,IAAA,YAAA;AAAA,MACE,EAAA;AAAA,QACE,MAAM;AACJ,UAAA,MAAM,CAAI,GAAA,OAAO,MAAW,KAAA,QAAA,GAAW,SAAS,MAAO,EAAA;AACvD,UAAO,OAAA;AAAA,YACL,MAAQ,EAAA,CAAA;AAAA,YACR,cAAc,YAAa;AAAA,WAC7B;AAAA,SACF;AAAA,QACA,CAAC,EAAE,MAAA,EAAQ,OAAS,EAAA,YAAA,EAAAA,eAAmB,KAAA;AACrC,UAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AACvC,UAAA,cAAA;AAAA,YACE,MAAM;AACJ,cAAIC,IAAAA,OAAAA,GACF,OAAmB,YAAA,OAAA,GAAU,OAAU,GAAA,IAAA;AACzC,cAAI,IAAA;AACF,gBAAA,IAAI,OAAO,OAAY,KAAA,QAAA;AACrB,kBAAAA,OAAAA,GAAS,QAAS,CAAA,aAAA,CAAc,OAAO,CAAA;AAAA,qBAAA,IAChC,OAAO,OAAA,KAAY,UAAY,EAAAA,UAAS,OAAQ,EAAA;AAAA,uBAClD,CAAG,EAAA;AACV;AAEF,cAAI,IAAA,CAACA,OAAU,IAAA,OAAO,OAAY,KAAA,QAAA;AAChC,gBAAO,OAAA,OAAA,CAAQ,KAAK,CAA6B,yBAAA,CAAA,EAAA;AAAA,kBAC/C,MAAQ,EAAA;AAAA,iBACT,CAAA;AAAA,mBAAA,IACM,CAACA,OAAAA;AACR,gBAAO,OAAA,OAAA,CAAQ,KAAK,CAA2B,yBAAA,CAAA,CAAA;AAEjD,cAAAA,OAAO,CAAA,gBAAA;AAAA,gBACL,gCAAA;AAAA,gBACA,MAAM;AACJ,kBAAA,UAAA,CAAW,MAAM,2BAA2B,CAAA;AAAA,iBAC9C;AAAA,gBACA,EAAE,MAAM,IAAK;AAAA,eACf;AAEA,cAAA,UAAA,CAAW,CAAC,OAAY,KAAA;AACtB,gBAAM,MAAA,CAAA,GAAI,sBAAuB,CAAA,OAAA,EAASA,OAAM,CAAA;AAEhD,gBAAM,MAAA,KAAA,GAAQ,EAAG,CAAA,CAAA,EAAmBD,aAAY,CAAA;AAEhD,gBAAA,SAAA,CAAU,MAAM;AACd,kBAAI,IAAA,OAAO,KAAU,KAAA,UAAA,EAAkB,KAAA,EAAA;AAAA,iBACxC,CAAA;AAED,gBAAW,UAAA,CAAA,MAAA,CAAO,gBAAiB,CAAA,OAAA,EAAS,OAAS,EAAA;AAAA,kBACnD,IAAM,EAAA;AAAA,iBACP,CAAA;AAAA,eACF,CAAA;AAAA,aACH;AAAA,YACA,EAAE,MAAQ,EAAA,UAAA,CAAW,MAAO;AAAA,WAC9B;AAGA,UAAA,SAAA,CAAU,MAAM;AACd,YAAA,UAAA,CAAW,MAAM,uBAAuB,CAAA;AAAA,WACzC,CAAA;AAAA;AACH;AACF,KACF;AAAA,GACF;AACF","file":"createWithElementContext.js","sourcesContent":["import type { createContext } from \"component-register\";\nimport { getContextFromProvider } from \"./getContextFromProvider.js\";\nimport { invokeOnLoaded } from \"./invokeOnLoaded.js\";\nimport {\n type Accessor,\n createEffect,\n createRoot,\n on,\n onCleanup,\n} from \"solid-js\";\n\n/**\n * Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.\n * */\n\nexport function createWithElementContext<\n Context extends ReturnType<typeof createContext>,\n ContextState = null,\n>(context: Context) {\n return function <D extends any>(\n target: string | Accessor<string> | Accessor<() => Element>,\n dependencies: Accessor<D> = () => null as D,\n cb: (context: ContextState, dependencies: D) => void | (() => void),\n ) {\n createEffect(\n on(\n () => {\n const t = typeof target === \"string\" ? target : target();\n return {\n target: t,\n dependencies: dependencies(),\n };\n },\n ({ target: _target, dependencies }) => {\n const controller = new AbortController();\n invokeOnLoaded(\n () => {\n let target: Element | null =\n _target instanceof Element ? _target : null;\n try {\n if (typeof _target === \"string\")\n target = document.querySelector(_target);\n else if (typeof _target === \"function\") target = _target();\n } catch (e) {\n e;\n }\n if (!target && typeof _target === \"string\")\n return console.warn(`Target element not found!`, {\n target: _target,\n });\n else if (!target)\n return console.warn(`Target element not found!`);\n\n target.addEventListener(\n \"bryt-designs:element-destroyed\",\n () => {\n controller.abort(\"Context element destroyed\");\n },\n { once: true },\n );\n\n createRoot((dispose) => {\n const c = getContextFromProvider(context, target);\n\n const unsub = cb(c as ContextState, dependencies);\n\n onCleanup(() => {\n if (typeof unsub === \"function\") unsub();\n });\n\n controller.signal.addEventListener(\"abort\", dispose, {\n once: true,\n });\n });\n },\n { signal: controller.signal },\n );\n\n // abort controller when dependencies change\n onCleanup(() => {\n controller.abort(\"Dependencies changed!\");\n });\n },\n ),\n );\n };\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function formatValue(format, value) {
|
|
2
|
+
switch (format) {
|
|
3
|
+
case "currency":
|
|
4
|
+
if (typeof value === "number") return window.Shopify.formatMoney(value);
|
|
5
|
+
if (typeof value === "string")
|
|
6
|
+
return window.Shopify.formatMoney(parseFloat(value));
|
|
7
|
+
console.warn("formatValue: Unsupported value type for currency format.");
|
|
8
|
+
return window.Shopify.formatMoney(0);
|
|
9
|
+
case "number":
|
|
10
|
+
return Number(value);
|
|
11
|
+
case "boolean":
|
|
12
|
+
return Boolean(value);
|
|
13
|
+
case "invert_boolean":
|
|
14
|
+
return !Boolean(value);
|
|
15
|
+
default:
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { formatValue };
|
|
21
|
+
//# sourceMappingURL=formatValue.js.map
|
|
22
|
+
//# sourceMappingURL=formatValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/formatValue.ts"],"names":[],"mappings":"AAOO,SAAS,WAAA,CAAY,QAAgB,KAAgB,EAAA;AAC1D,EAAA,QAAQ,MAAQ;AAAA,IACd,KAAK,UAAA;AACH,MAAA,IAAI,OAAO,KAAU,KAAA,QAAA,SAAiB,MAAO,CAAA,OAAA,CAAQ,YAAY,KAAK,CAAA;AACtE,MAAA,IAAI,OAAO,KAAU,KAAA,QAAA;AACnB,QAAA,OAAO,MAAO,CAAA,OAAA,CAAQ,WAAY,CAAA,UAAA,CAAW,KAAK,CAAC,CAAA;AACrD,MAAA,OAAA,CAAQ,KAAK,0DAA0D,CAAA;AACvE,MAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,WAAA,CAAY,CAAC,CAAA;AAAA,IACrC,KAAK,QAAA;AACH,MAAA,OAAO,OAAO,KAAK,CAAA;AAAA,IACrB,KAAK,SAAA;AACH,MAAA,OAAO,QAAQ,KAAK,CAAA;AAAA,IACtB,KAAK,gBAAA;AACH,MAAO,OAAA,CAAC,QAAQ,KAAK,CAAA;AAAA,IACvB;AACE,MAAO,OAAA,KAAA;AAAA;AAEb","file":"formatValue.js","sourcesContent":["export type Format =\n | \"currency\"\n | \"number\"\n | \"boolean\"\n | \"invert_boolean\"\n | string;\n\nexport function formatValue(format: Format, value: unknown) {\n switch (format) {\n case \"currency\":\n if (typeof value === \"number\") return window.Shopify.formatMoney(value);\n if (typeof value === \"string\")\n return window.Shopify.formatMoney(parseFloat(value));\n console.warn(\"formatValue: Unsupported value type for currency format.\");\n return window.Shopify.formatMoney(0);\n case \"number\":\n return Number(value);\n case \"boolean\":\n return Boolean(value);\n case \"invert_boolean\":\n return !Boolean(value);\n default:\n return value as any;\n }\n}\n\ndeclare global {\n interface Window {\n Shopify: {\n formatMoney(value: number, currency?: string): string;\n };\n }\n}\n"]}
|
|
@@ -21,6 +21,8 @@ export declare function invokeOnLoaded(fn: () => void, { signal }: {
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates a HOF to ensure that a given callback is invoked only after the context for the element is ready.
|
|
23
23
|
* */
|
|
24
|
-
export declare function createWithElementContext<Context extends ReturnType<typeof createContext>, ContextState = null>(context: Context): <D extends any>(
|
|
24
|
+
export declare function createWithElementContext<Context extends ReturnType<typeof createContext>, ContextState = null>(context: Context): <D extends any>(target: string | Accessor<string> | Accessor<() => Element>, dependencies: Accessor<D> | undefined, cb: (context: ContextState, dependencies: D) => void | (() => void)) => void;
|
|
25
|
+
export type Format = "currency" | "number" | "boolean" | "invert_boolean" | string;
|
|
26
|
+
export declare function formatValue(format: Format, value: unknown): any;
|
|
25
27
|
|
|
26
28
|
export {};
|
package/dist/main/utils/index.js
CHANGED
|
@@ -5,5 +5,6 @@ export * from './getContextFromProvider.js';
|
|
|
5
5
|
export * from './checkLoaded.js';
|
|
6
6
|
export * from './invokeOnLoaded.js';
|
|
7
7
|
export * from './createWithElementContext.js';
|
|
8
|
+
export * from './formatValue.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compose, register, noShadowDOM } from 'component-register';
|
|
2
|
-
import { createRoot, createSignal } from 'solid-js';
|
|
2
|
+
import { onCleanup, createRoot, createSignal } from 'solid-js';
|
|
3
3
|
import { insert } from 'solid-js/web';
|
|
4
4
|
|
|
5
5
|
function createProps(raw) {
|
|
@@ -55,6 +55,15 @@ function customElement(tagName, props, Component = () => {
|
|
|
55
55
|
}, ...rest) {
|
|
56
56
|
return compose(register(tagName, props), withSolid, ...rest)(Component);
|
|
57
57
|
}
|
|
58
|
+
function isConstructable(fn) {
|
|
59
|
+
if (typeof fn !== "function") return false;
|
|
60
|
+
try {
|
|
61
|
+
Reflect.construct(String, [], fn);
|
|
62
|
+
return true;
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
58
67
|
function customShadowlessElement(tagName, props, Component = () => {
|
|
59
68
|
}, ...rest) {
|
|
60
69
|
return compose(
|
|
@@ -62,7 +71,16 @@ function customShadowlessElement(tagName, props, Component = () => {
|
|
|
62
71
|
withNoShadowDOM,
|
|
63
72
|
withSolid,
|
|
64
73
|
...rest
|
|
65
|
-
)(
|
|
74
|
+
)((...args) => {
|
|
75
|
+
onCleanup(() => {
|
|
76
|
+
const [_, { element }] = args;
|
|
77
|
+
element.dispatchEvent(new CustomEvent("bryt-designs:element-destroyed"));
|
|
78
|
+
});
|
|
79
|
+
if (isConstructable(Component)) {
|
|
80
|
+
return new Component(...args);
|
|
81
|
+
}
|
|
82
|
+
return Component(...args);
|
|
83
|
+
});
|
|
66
84
|
}
|
|
67
85
|
const correctElementType = (component) => {
|
|
68
86
|
return (props, options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/solid-element.ts"],"names":[],"mappings":";;;;AAqBA,SAAS,YAA8B,GAAQ,EAAA;AAC7C,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,IAAA,CAAK,GAAG,CAAA;AAC5B,EAAA,MAAM,QAAQ,EAAC;AACf,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,IAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAClB,IAAI,IAAA,OAAO,QAAQ,WAAa,EAAA;AAChC,IAAM,MAAA,CAAC,KAAK,GAAG,CAAA,GAAI,aAAa,OAAQ,CAAA,GAAA,CAAI,GAAK,EAAA,GAAG,CAAC,CAAA;AACrD,IAAO,MAAA,CAAA,cAAA,CAAe,OAAO,GAAK,EAAA;AAAA,MAChC,GAAA;AAAA,MACA,IAAI,CAAG,EAAA;AACL,QAAA,GAAA,CAAI,MAAM,CAAC,CAAA;AAAA;AACb,KACD,CAAA;AAAA;AAEH,EAAO,OAAA,KAAA;AACT;AAEA,SAAS,cAAc,EAAwC,EAAA;A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C,SACqB,KAAA;AACrB,EAAO,OAAA,CAAC,OAAU,OAAY,KAAA;AAC5B,IAAO,OAAA,SAAA,CAAU,OAAO,OAAkC,CAAA;AAAA,GAC5D;AACF","file":"solid-element.js","sourcesContent":["import {\n register,\n type ComponentType as mComponentType,\n type ICustomElement,\n type FunctionComponent,\n type ComponentOptions,\n noShadowDOM,\n compose,\n} from \"component-register\";\nimport { createRoot, createSignal, onCleanup } from \"solid-js\";\nimport { insert } from \"solid-js/web\";\n\nexport type ComponentType<T> = mComponentType<T>;\n\ntype CorrectComponentOptions = { element: HTMLElement & ICustomElement };\n\nexport type CorrectComponentType<T> = (\n props: T,\n options: CorrectComponentOptions,\n) => unknown;\n\nfunction createProps<T extends object>(raw: T) {\n const keys = Object.keys(raw) as (keyof T)[];\n const props = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (typeof key === \"undefined\") continue;\n const [get, set] = createSignal(Reflect.get(raw, key));\n Object.defineProperty(props, key, {\n get,\n set(v) {\n set(() => v);\n },\n });\n }\n return props as T;\n}\n\nfunction lookupContext(el: ICustomElement & { _$owner?: any }) {\n if (el.assignedSlot && el.assignedSlot._$owner)\n return el.assignedSlot._$owner;\n let next: Element & { _$owner?: any } = el.parentNode;\n while (\n next &&\n !next._$owner &&\n !(\n next.assignedSlot &&\n (next.assignedSlot as Element & { _$owner?: any })._$owner\n )\n )\n next = next.parentNode as Element;\n return next && next.assignedSlot\n ? (next.assignedSlot as Element & { _$owner?: any })._$owner\n : el._$owner;\n}\n\nfunction withSolid<T extends object>(\n ComponentType: ComponentType<T>,\n): ComponentType<T> {\n return (rawProps: T, options: ComponentOptions) => {\n const { element } = options as {\n element: ICustomElement & { _$owner?: any };\n };\n return createRoot((dispose: Function) => {\n const props = createProps<T>(rawProps);\n\n element.addPropertyChangedCallback(\n (key: string, val: any) => (props[key as keyof T] = val),\n );\n element.addReleaseCallback(() => {\n element.renderRoot.textContent = \"\";\n dispose();\n });\n\n const comp = (ComponentType as FunctionComponent<T>)(props as T, options);\n return insert(element.renderRoot, comp);\n }, lookupContext(element));\n };\n}\n\nfunction withNoShadowDOM<T extends object>(\n Component: ComponentType<T> = () => {},\n) {\n return (props: T, options: ComponentOptions) => {\n noShadowDOM();\n const comp = (Component as FunctionComponent<T>)(props, options);\n return comp;\n };\n}\n\nexport function customElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(register(tagName, props), withSolid, ...rest)(Component);\n}\n\nfunction isConstructable(fn: unknown): fn is new (...args: any[]) => any {\n if (typeof fn !== \"function\") return false;\n\n try {\n Reflect.construct(String, [], fn as Function);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function customShadowlessElement<T extends object>(\n tagName: string,\n props: T,\n Component: ComponentType<T> = () => {},\n ...rest: ((C: ComponentType<T>) => ComponentType<T>)[]\n) {\n return compose(\n register(tagName, props),\n withNoShadowDOM,\n withSolid,\n ...rest,\n )((...args) => {\n onCleanup(() => {\n const [_, { element }] = args;\n element.dispatchEvent(new CustomEvent(\"bryt-designs:element-destroyed\"));\n });\n if (isConstructable(Component)) {\n return new Component(...args);\n }\n return Component(...args);\n });\n}\n\nexport const correctElementType = <T>(\n component: CorrectComponentType<T>,\n): ComponentType<T> => {\n return (props: T, options) => {\n return component(props, options as CorrectComponentOptions);\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brytdesigns/web-component-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Web component core utilities for building solid based web components",
|
|
5
5
|
"main": "./dist/main/index.js",
|
|
6
6
|
"module": "./dist/main/index.js",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"./utils": {
|
|
27
27
|
"types": "./dist/main/utils/index.d.ts",
|
|
28
28
|
"module": "./dist/main/utils/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./hooks": {
|
|
31
|
+
"types": "./dist/main/hooks/index.d.ts",
|
|
32
|
+
"module": "./dist/main/hooks/index.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"files": [
|
|
@@ -38,7 +42,7 @@
|
|
|
38
42
|
"component-register": "^0.8.7",
|
|
39
43
|
"focus-trap": "^7.6.4",
|
|
40
44
|
"motion": "^12.18.1",
|
|
41
|
-
"solid-js": "^1.9.
|
|
45
|
+
"solid-js": "^1.9.9"
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"dts-bundle-generator": "^9.5.1",
|