@brytdesigns/web-component-core 1.1.2 → 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 +99 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.js +21 -1
- 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 +28 -1
- package/dist/main/index.js +1 -0
- package/dist/main/utils/formatValue.js +22 -0
- package/dist/main/utils/formatValue.js.map +1 -0
- package/dist/main/utils/index.d.ts +2 -0
- package/dist/main/utils/index.js +1 -0
- 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,EAAA,OAAO,KAAK,KAAM,CAAA,GAAG,EAAE,MAAY,CAAA,CAAC,KAAK,GAAQ,KAAA;AAC/C,IAAA,IAAI,GAAQ,KAAA,IAAA,IAA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M,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
2
|
import { createMemo, onCleanup, createEffect, on, createRoot, createSignal } from 'solid-js';
|
|
3
|
-
import { compose, register, noShadowDOM } from 'component-register';
|
|
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
|
|
@@ -308,6 +308,103 @@ function createWithElementContext(context) {
|
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
|
|
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 };
|
|
312
409
|
//# sourceMappingURL=index.js.map
|
|
313
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","dependencies","target","createRoot","onCleanup"],"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,O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BAAI,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,UAAAA,UAAU,MAAM;AACd,YAAA,UAAA,CAAW,MAAM,uBAAuB,CAAA;AAAA,WACzC,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, 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"]}
|
|
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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AI,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,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
|
@@ -184,6 +184,26 @@ function createWithElementContext(context) {
|
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
|
|
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 };
|
|
188
208
|
//# sourceMappingURL=index.js.map
|
|
189
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":["dependencies","target","createRoot","onCleanup"],"mappings":";;;;;AAAO,SAAS,aAAa,GAAqB,EAAA;AAChD,EAAA,OAAO,GACJ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AAA,WACzC,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, 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"]}
|
|
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,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;AAC7D,EAAI,IAAA,EAAA,CAAG,YAAgB,IAAA,EAAA,CAAG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-$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;AAC1B,IAAA,OAAO,OAAQ,CAAA,IAAA;AAAA;AAGjB,EAAM,MAAA,OAAA,GAAU,cAAc,6BAA6B,CAAA;AAE3D,EAAA,SAASA,SAAQ,CAAA;AAAA,IACf,OAAA;AAAA,IACA;AAAA,GAI8B,EAAA;AAC9B,IAAA,OAAOC,OAAS,CAAA,OAAA,EAAS,EAAE,IAAA,IAAQ,OAAO,CAAA;AAAA;AAG5C,EAAA,SAAS,2BAA2B,OAAsC,EAAA;AACxE,IAAO,OAAA,OAAA;AAAA;AAGT,EAAA,SAAS,QAAQ,KAGY,EAAA;AAC3B,IAAA,MAAM,OAAU,GAAAC,OAAA,CAAS,OAAS,EAAA,KAAA,CAAM,OAAO,CAAA;AAC/C,IAAM,MAAA,QAAA,GAAW,2BAA2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A,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';
|
|
@@ -52,5 +52,32 @@ export declare function invokeOnLoaded(fn: () => void, { signal }: {
|
|
|
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
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
|
@@ -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"]}
|
|
@@ -22,5 +22,7 @@ export declare function invokeOnLoaded(fn: () => void, { signal }: {
|
|
|
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
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
|
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",
|