regor 1.5.3 → 1.5.5
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/README.md +1 -0
- package/dist/regor.d.ts +26 -13
- package/dist/regor.es2015.cjs.js +41 -23
- package/dist/regor.es2015.cjs.prod.js +3 -3
- package/dist/regor.es2015.esm.js +41 -23
- package/dist/regor.es2015.esm.prod.js +3 -3
- package/dist/regor.es2015.iife.js +41 -23
- package/dist/regor.es2015.iife.prod.js +3 -3
- package/dist/regor.es2019.cjs.js +41 -23
- package/dist/regor.es2019.cjs.prod.js +3 -3
- package/dist/regor.es2019.esm.js +41 -23
- package/dist/regor.es2019.esm.prod.js +3 -3
- package/dist/regor.es2019.iife.js +41 -23
- package/dist/regor.es2019.iife.prod.js +3 -3
- package/dist/regor.es2022.cjs.js +33 -16
- package/dist/regor.es2022.cjs.prod.js +3 -3
- package/dist/regor.es2022.esm.js +33 -16
- package/dist/regor.es2022.esm.prod.js +3 -3
- package/dist/regor.es2022.iife.js +33 -16
- package/dist/regor.es2022.iife.prod.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -411,6 +411,7 @@ These directives empower you to create dynamic and interactive user interfaces,
|
|
|
411
411
|
- **`persist`** Persists a given ref in local storage reactively.
|
|
412
412
|
- **`html`** A tag to produce HTML string using template literals. Recommended to use with the VS-Code [`lit-html`](https://marketplace.visualstudio.com/items?itemName=bierner.lit-html) extension for formatting and highlighting.
|
|
413
413
|
- **`raw`** A tag to produce HTML string, similar to `html`, but it is excluded from formatting when [`lit-html`](https://marketplace.visualstudio.com/items?itemName=bierner.lit-html) extension is installed.
|
|
414
|
+
- **`svg`** A tag to produce SVG template strings with the same interpolation behavior as `html`.
|
|
414
415
|
|
|
415
416
|
**Observe Functions**
|
|
416
417
|
|
package/dist/regor.d.ts
CHANGED
|
@@ -147,24 +147,36 @@ export declare class ComponentHead<TContext extends IRegorContext | object = IRe
|
|
|
147
147
|
*/
|
|
148
148
|
ctx: IRegorContext[];
|
|
149
149
|
/**
|
|
150
|
-
* Controls whether Regor
|
|
151
|
-
*
|
|
150
|
+
* Controls whether Regor automatically merges parent-provided component inputs
|
|
151
|
+
* into the object returned by `context(head)`.
|
|
152
152
|
*
|
|
153
|
-
*
|
|
153
|
+
* There are two runtime data sources for a component:
|
|
154
|
+
*
|
|
155
|
+
* 1. Parent inputs:
|
|
156
|
+
* values passed from the component host, such as `:title="abc"` or
|
|
157
|
+
* `:context="{ ... }"`. These are exposed on `head.props`.
|
|
158
|
+
*
|
|
159
|
+
* 2. Component context:
|
|
160
|
+
* the object returned by `context(head)`. This is the component's own local
|
|
161
|
+
* state.
|
|
162
|
+
*
|
|
163
|
+
* `autoProps` controls the third step: how those two sources are merged.
|
|
154
164
|
*
|
|
155
165
|
* - `true` (default):
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* - `false`:
|
|
161
|
-
* - Regor does not auto-apply props.
|
|
162
|
-
* - You fully control mapping manually inside `context(head)`.
|
|
166
|
+
* Regor automatically applies `head.props` to the component context.
|
|
167
|
+
* If a parent input name is missing from the component context, Regor adds it.
|
|
168
|
+
* Isolates the declared component properties,
|
|
169
|
+
* so a component does not accidentally inherit unwanted values from its ancestors.
|
|
163
170
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
171
|
+
* - `false`:
|
|
172
|
+
* Regor does not merge `head.props` into the returned context.
|
|
173
|
+
* The component author must map values manually from `head.props`.
|
|
174
|
+
* Disables isolation for declared props.
|
|
166
175
|
*
|
|
167
|
-
*
|
|
176
|
+
* In short:
|
|
177
|
+
* - `head.props` = what the parent passed
|
|
178
|
+
* - `context(head)` return value = what the component defines
|
|
179
|
+
* - `autoProps` = whether Regor should merge the first into the second
|
|
168
180
|
*
|
|
169
181
|
* Example (auto add):
|
|
170
182
|
* ```ts
|
|
@@ -732,6 +744,7 @@ export declare const markRaw: <TValueType extends object>(value: TValueType) =>
|
|
|
732
744
|
export declare const persist: <TRef extends AnyRef>(anyRef: TRef, key: string) => TRef;
|
|
733
745
|
export declare const html: (templates: TemplateStringsArray, ...args: unknown[]) => string;
|
|
734
746
|
export declare const raw: (templates: TemplateStringsArray, ...args: unknown[]) => string;
|
|
747
|
+
export declare const svg: (templates: TemplateStringsArray, ...args: unknown[]) => string;
|
|
735
748
|
export declare const observe: <TValueType extends AnyRef>(source: TValueType, observer: ObserveCallback<UnwrapRef<TValueType>>, init?: boolean, trackUnmount?: boolean) => StopObserving;
|
|
736
749
|
export type ObserveManySourceValues<TSources extends readonly AnyRef[]> = {
|
|
737
750
|
[TIndex in keyof TSources]: UnwrapRef<TSources[TIndex]>;
|
package/dist/regor.es2015.cjs.js
CHANGED
|
@@ -95,6 +95,7 @@ __export(index_exports, {
|
|
|
95
95
|
silence: () => silence,
|
|
96
96
|
sref: () => sref,
|
|
97
97
|
startBatch: () => startBatch,
|
|
98
|
+
svg: () => svg,
|
|
98
99
|
toFragment: () => toFragment,
|
|
99
100
|
toJsonTemplate: () => toJsonTemplate,
|
|
100
101
|
trigger: () => trigger,
|
|
@@ -555,24 +556,36 @@ var ComponentHead = class {
|
|
|
555
556
|
*/
|
|
556
557
|
__publicField(this, "ctx");
|
|
557
558
|
/**
|
|
558
|
-
* Controls whether Regor
|
|
559
|
-
*
|
|
559
|
+
* Controls whether Regor automatically merges parent-provided component inputs
|
|
560
|
+
* into the object returned by `context(head)`.
|
|
560
561
|
*
|
|
561
|
-
*
|
|
562
|
+
* There are two runtime data sources for a component:
|
|
563
|
+
*
|
|
564
|
+
* 1. Parent inputs:
|
|
565
|
+
* values passed from the component host, such as `:title="abc"` or
|
|
566
|
+
* `:context="{ ... }"`. These are exposed on `head.props`.
|
|
567
|
+
*
|
|
568
|
+
* 2. Component context:
|
|
569
|
+
* the object returned by `context(head)`. This is the component's own local
|
|
570
|
+
* state.
|
|
571
|
+
*
|
|
572
|
+
* `autoProps` controls the third step: how those two sources are merged.
|
|
562
573
|
*
|
|
563
574
|
* - `true` (default):
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
* - `false`:
|
|
569
|
-
* - Regor does not auto-apply props.
|
|
570
|
-
* - You fully control mapping manually inside `context(head)`.
|
|
575
|
+
* Regor automatically applies `head.props` to the component context.
|
|
576
|
+
* If a parent input name is missing from the component context, Regor adds it.
|
|
577
|
+
* Isolates the declared component properties,
|
|
578
|
+
* so a component does not accidentally inherit unwanted values from its ancestors.
|
|
571
579
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
580
|
+
* - `false`:
|
|
581
|
+
* Regor does not merge `head.props` into the returned context.
|
|
582
|
+
* The component author must map values manually from `head.props`.
|
|
583
|
+
* Disables isolation for declared props.
|
|
574
584
|
*
|
|
575
|
-
*
|
|
585
|
+
* In short:
|
|
586
|
+
* - `head.props` = what the parent passed
|
|
587
|
+
* - `context(head)` return value = what the component defines
|
|
588
|
+
* - `autoProps` = whether Regor should merge the first into the second
|
|
576
589
|
*
|
|
577
590
|
* Example (auto add):
|
|
578
591
|
* ```ts
|
|
@@ -1681,6 +1694,7 @@ var ComponentBinder = class {
|
|
|
1681
1694
|
return isTemplate(node) && node.getAttributeNames().length === 0;
|
|
1682
1695
|
}
|
|
1683
1696
|
__unwrapComponents(element) {
|
|
1697
|
+
var _a, _b;
|
|
1684
1698
|
const binder = this.__binder;
|
|
1685
1699
|
const parser = binder.__parser;
|
|
1686
1700
|
const registeredComponents = binder.__config.__components;
|
|
@@ -1714,6 +1728,7 @@ var ComponentBinder = class {
|
|
|
1714
1728
|
const contextName = binder.__config.__builtInNames.context;
|
|
1715
1729
|
const contextAliasName = binder.__config.__builtInNames.contextAlias;
|
|
1716
1730
|
const bindName = binder.__config.__builtInNames.bind;
|
|
1731
|
+
const definedProps = (_b = (_a = registeredComponent.props) == null ? void 0 : _a.map(camelize)) != null ? _b : [];
|
|
1717
1732
|
const getProps = (component2, capturedContext2) => {
|
|
1718
1733
|
const props = {};
|
|
1719
1734
|
const hasContext = component2.hasAttribute(contextName);
|
|
@@ -1724,9 +1739,7 @@ var ComponentBinder = class {
|
|
|
1724
1739
|
} else if (component2.hasAttribute(contextAliasName)) {
|
|
1725
1740
|
binder.__bind(contextDirective, component2, contextAliasName);
|
|
1726
1741
|
}
|
|
1727
|
-
|
|
1728
|
-
if (!definedProps || definedProps.length === 0) return;
|
|
1729
|
-
definedProps = definedProps.map(camelize);
|
|
1742
|
+
if (definedProps.length === 0) return;
|
|
1730
1743
|
const definedPropsByLowerCase = new Map(
|
|
1731
1744
|
definedProps.map((definedProp) => [
|
|
1732
1745
|
definedProp.toLowerCase(),
|
|
@@ -1765,7 +1778,7 @@ var ComponentBinder = class {
|
|
|
1765
1778
|
};
|
|
1766
1779
|
const capturedContext = [...parser.__capture()];
|
|
1767
1780
|
const createComponentCtx = () => {
|
|
1768
|
-
var
|
|
1781
|
+
var _a2;
|
|
1769
1782
|
const props = getProps(component, capturedContext);
|
|
1770
1783
|
const head2 = new ComponentHead(
|
|
1771
1784
|
props,
|
|
@@ -1776,8 +1789,8 @@ var ComponentBinder = class {
|
|
|
1776
1789
|
binder.__config.propValidationMode
|
|
1777
1790
|
);
|
|
1778
1791
|
const componentCtx2 = useScope(() => {
|
|
1779
|
-
var
|
|
1780
|
-
return (
|
|
1792
|
+
var _a3;
|
|
1793
|
+
return (_a3 = registeredComponent.context(head2)) != null ? _a3 : {};
|
|
1781
1794
|
}).context;
|
|
1782
1795
|
if (head2.autoProps) {
|
|
1783
1796
|
for (const [key, propsValue] of Object.entries(props)) {
|
|
@@ -1801,7 +1814,11 @@ var ComponentBinder = class {
|
|
|
1801
1814
|
}
|
|
1802
1815
|
} else componentCtx2[key] = propsValue;
|
|
1803
1816
|
}
|
|
1804
|
-
(
|
|
1817
|
+
for (const key of definedProps) {
|
|
1818
|
+
if (key in componentCtx2) continue;
|
|
1819
|
+
componentCtx2[key] = void 0;
|
|
1820
|
+
}
|
|
1821
|
+
(_a2 = head2.onAutoPropsAssigned) == null ? void 0 : _a2.call(head2);
|
|
1805
1822
|
}
|
|
1806
1823
|
return { componentCtx: componentCtx2, head: head2 };
|
|
1807
1824
|
};
|
|
@@ -1810,7 +1827,7 @@ var ComponentBinder = class {
|
|
|
1810
1827
|
const len = childNodes.length;
|
|
1811
1828
|
const isEmptyComponent = component.childNodes.length === 0;
|
|
1812
1829
|
const expandSlot = (slot) => {
|
|
1813
|
-
var
|
|
1830
|
+
var _a2;
|
|
1814
1831
|
const parent2 = slot.parentElement;
|
|
1815
1832
|
let name = slot.name;
|
|
1816
1833
|
if (isNullOrWhitespace(name)) {
|
|
@@ -1843,9 +1860,9 @@ var ComponentBinder = class {
|
|
|
1843
1860
|
const unnamedTemplates = component.querySelectorAll(
|
|
1844
1861
|
"template:not([name])"
|
|
1845
1862
|
);
|
|
1846
|
-
compTemplate = (
|
|
1863
|
+
compTemplate = (_a2 = [...unnamedTemplates].find(
|
|
1847
1864
|
(x) => this.__isDefaultSlotTemplateShortcut(x)
|
|
1848
|
-
)) != null ?
|
|
1865
|
+
)) != null ? _a2 : null;
|
|
1849
1866
|
}
|
|
1850
1867
|
const createSwitchContext = (childNodes2) => {
|
|
1851
1868
|
if (!head.enableSwitch) return;
|
|
@@ -6752,6 +6769,7 @@ var html = (templates, ...args) => {
|
|
|
6752
6769
|
return result;
|
|
6753
6770
|
};
|
|
6754
6771
|
var raw = html;
|
|
6772
|
+
var svg = html;
|
|
6755
6773
|
|
|
6756
6774
|
// src/observer/observeMany.ts
|
|
6757
6775
|
var observeMany = (sources, observer, init) => {
|