thunderous 0.4.3 → 0.6.0
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/index.cjs +45 -15
- package/dist/index.d.cts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.js +45 -15
- package/package.json +9 -1
package/dist/index.cjs
CHANGED
@@ -1233,6 +1233,8 @@ var customElement = (render, options) => {
|
|
1233
1233
|
shadowRootOptions: _shadowRootOptions
|
1234
1234
|
} = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1235
1235
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
1236
|
+
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1237
|
+
console.log(shadowRootOptions);
|
1236
1238
|
const observedAttributesSet = new Set(_observedAttributes);
|
1237
1239
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1238
1240
|
for (const [attrName, coerce] of attributesAsProperties) {
|
@@ -1372,6 +1374,7 @@ You must set an initial value before calling a property signal's getter.
|
|
1372
1374
|
});
|
1373
1375
|
fragment.host = this;
|
1374
1376
|
setInnerHTML(root, fragment);
|
1377
|
+
root.innerHTML = root.innerHTML;
|
1375
1378
|
}
|
1376
1379
|
static get formAssociated() {
|
1377
1380
|
return formAssociated;
|
@@ -1467,39 +1470,66 @@ You must set an initial value before calling a property signal's getter.
|
|
1467
1470
|
}
|
1468
1471
|
}
|
1469
1472
|
}
|
1470
|
-
let
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1473
|
+
let _tagName = null;
|
1474
|
+
let _registry = null;
|
1475
|
+
let _registered = false;
|
1476
|
+
const register = () => {
|
1477
|
+
if (_tagName === null || _registry === null || _registered) return;
|
1478
|
+
_registry.register(_tagName, CustomElement);
|
1479
|
+
_registry.register(_tagName, elementResult);
|
1480
|
+
_registered = true;
|
1481
|
+
};
|
1482
|
+
const elementResult = {
|
1483
|
+
define(tagName) {
|
1484
|
+
const registry = _registry?.scoped ? _registry.eject() : customElements;
|
1485
|
+
console.log(tagName, registry);
|
1486
|
+
if (registry.get(tagName) !== void 0) {
|
1487
|
+
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1475
1488
|
return this;
|
1476
1489
|
}
|
1477
|
-
|
1478
|
-
|
1490
|
+
registry.define(tagName, CustomElement);
|
1491
|
+
_tagName = tagName;
|
1492
|
+
register();
|
1479
1493
|
return this;
|
1480
1494
|
},
|
1481
1495
|
register(registry) {
|
1482
|
-
if (
|
1483
|
-
console.error("
|
1496
|
+
if (_tagName !== null && registry.scoped) {
|
1497
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
1484
1498
|
return this;
|
1485
1499
|
}
|
1486
|
-
registry
|
1500
|
+
_registry = registry;
|
1501
|
+
register();
|
1487
1502
|
return this;
|
1488
1503
|
},
|
1489
1504
|
eject: () => CustomElement
|
1490
1505
|
};
|
1506
|
+
return elementResult;
|
1491
1507
|
};
|
1492
|
-
var createRegistry = () => {
|
1493
|
-
const
|
1508
|
+
var createRegistry = (args) => {
|
1509
|
+
const { scoped = false } = args ?? {};
|
1510
|
+
const registryResult = /* @__PURE__ */ new Map();
|
1511
|
+
const registry = (() => {
|
1512
|
+
try {
|
1513
|
+
return new CustomElementRegistry();
|
1514
|
+
} catch (error) {
|
1515
|
+
if (scoped)
|
1516
|
+
console.error(
|
1517
|
+
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1518
|
+
);
|
1519
|
+
return customElements;
|
1520
|
+
}
|
1521
|
+
})();
|
1494
1522
|
return {
|
1495
1523
|
register: (tagName, element) => {
|
1496
|
-
if (
|
1524
|
+
if (registryResult.has(element)) {
|
1497
1525
|
console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
|
1498
1526
|
return;
|
1499
1527
|
}
|
1500
|
-
|
1528
|
+
registryResult.set(element, tagName.toUpperCase());
|
1501
1529
|
},
|
1502
|
-
getTagName: (element) =>
|
1530
|
+
getTagName: (element) => registryResult.get(element),
|
1531
|
+
eject: () => registry,
|
1532
|
+
scoped
|
1503
1533
|
};
|
1504
1534
|
};
|
1505
1535
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
@@ -52,7 +52,7 @@ declare global {
|
|
52
52
|
}
|
53
53
|
type ElementResult = {
|
54
54
|
define: (tagname: `${string}-${string}`) => ElementResult;
|
55
|
-
register: (registry:
|
55
|
+
register: (registry: RegistryResult) => ElementResult;
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
@@ -83,7 +83,10 @@ type RenderOptions = {
|
|
83
83
|
observedAttributes: string[];
|
84
84
|
attributesAsProperties: [string, Coerce][];
|
85
85
|
attachShadow: boolean;
|
86
|
-
shadowRootOptions: ShadowRootInit
|
86
|
+
shadowRootOptions: Partial<ShadowRootInit> & {
|
87
|
+
customElements?: CustomElementRegistry;
|
88
|
+
registry?: CustomElementRegistry | RegistryResult;
|
89
|
+
};
|
87
90
|
};
|
88
91
|
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
92
|
/**
|
@@ -97,12 +100,22 @@ type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>
|
|
97
100
|
* ```
|
98
101
|
*/
|
99
102
|
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
100
|
-
type
|
101
|
-
register: (tagName: string,
|
102
|
-
getTagName: (
|
103
|
+
type RegistryResult = {
|
104
|
+
register: (tagName: string, CustomElement: CustomElementConstructor | ElementResult) => void;
|
105
|
+
getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
|
106
|
+
eject: () => CustomElementRegistry;
|
107
|
+
scoped: boolean;
|
108
|
+
};
|
109
|
+
type RegistryArgs = {
|
110
|
+
scoped: boolean;
|
103
111
|
};
|
104
112
|
/**
|
105
113
|
* Create a registry for custom elements.
|
114
|
+
*
|
115
|
+
* This allows you to delegate custom element definitions to the consumer of your library,
|
116
|
+
* by using their associated classes to look up tag names dynamically.
|
117
|
+
*
|
118
|
+
* This can be useful when you need to select a custom element whose tag name is variable.
|
106
119
|
* @example
|
107
120
|
* ```ts
|
108
121
|
* const registry = createRegistry();
|
@@ -111,6 +124,6 @@ type Registry = {
|
|
111
124
|
* console.log(tagName); // 'MY-ELEMENT'
|
112
125
|
* ```
|
113
126
|
*/
|
114
|
-
declare const createRegistry: () =>
|
127
|
+
declare const createRegistry: (args?: RegistryArgs) => RegistryResult;
|
115
128
|
|
116
129
|
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.d.ts
CHANGED
@@ -52,7 +52,7 @@ declare global {
|
|
52
52
|
}
|
53
53
|
type ElementResult = {
|
54
54
|
define: (tagname: `${string}-${string}`) => ElementResult;
|
55
|
-
register: (registry:
|
55
|
+
register: (registry: RegistryResult) => ElementResult;
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
@@ -83,7 +83,10 @@ type RenderOptions = {
|
|
83
83
|
observedAttributes: string[];
|
84
84
|
attributesAsProperties: [string, Coerce][];
|
85
85
|
attachShadow: boolean;
|
86
|
-
shadowRootOptions: ShadowRootInit
|
86
|
+
shadowRootOptions: Partial<ShadowRootInit> & {
|
87
|
+
customElements?: CustomElementRegistry;
|
88
|
+
registry?: CustomElementRegistry | RegistryResult;
|
89
|
+
};
|
87
90
|
};
|
88
91
|
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
92
|
/**
|
@@ -97,12 +100,22 @@ type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>
|
|
97
100
|
* ```
|
98
101
|
*/
|
99
102
|
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
100
|
-
type
|
101
|
-
register: (tagName: string,
|
102
|
-
getTagName: (
|
103
|
+
type RegistryResult = {
|
104
|
+
register: (tagName: string, CustomElement: CustomElementConstructor | ElementResult) => void;
|
105
|
+
getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
|
106
|
+
eject: () => CustomElementRegistry;
|
107
|
+
scoped: boolean;
|
108
|
+
};
|
109
|
+
type RegistryArgs = {
|
110
|
+
scoped: boolean;
|
103
111
|
};
|
104
112
|
/**
|
105
113
|
* Create a registry for custom elements.
|
114
|
+
*
|
115
|
+
* This allows you to delegate custom element definitions to the consumer of your library,
|
116
|
+
* by using their associated classes to look up tag names dynamically.
|
117
|
+
*
|
118
|
+
* This can be useful when you need to select a custom element whose tag name is variable.
|
106
119
|
* @example
|
107
120
|
* ```ts
|
108
121
|
* const registry = createRegistry();
|
@@ -111,6 +124,6 @@ type Registry = {
|
|
111
124
|
* console.log(tagName); // 'MY-ELEMENT'
|
112
125
|
* ```
|
113
126
|
*/
|
114
|
-
declare const createRegistry: () =>
|
127
|
+
declare const createRegistry: (args?: RegistryArgs) => RegistryResult;
|
115
128
|
|
116
129
|
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.js
CHANGED
@@ -1201,6 +1201,8 @@ var customElement = (render, options) => {
|
|
1201
1201
|
shadowRootOptions: _shadowRootOptions
|
1202
1202
|
} = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1203
1203
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
1204
|
+
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1205
|
+
console.log(shadowRootOptions);
|
1204
1206
|
const observedAttributesSet = new Set(_observedAttributes);
|
1205
1207
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1206
1208
|
for (const [attrName, coerce] of attributesAsProperties) {
|
@@ -1340,6 +1342,7 @@ You must set an initial value before calling a property signal's getter.
|
|
1340
1342
|
});
|
1341
1343
|
fragment.host = this;
|
1342
1344
|
setInnerHTML(root, fragment);
|
1345
|
+
root.innerHTML = root.innerHTML;
|
1343
1346
|
}
|
1344
1347
|
static get formAssociated() {
|
1345
1348
|
return formAssociated;
|
@@ -1435,39 +1438,66 @@ You must set an initial value before calling a property signal's getter.
|
|
1435
1438
|
}
|
1436
1439
|
}
|
1437
1440
|
}
|
1438
|
-
let
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1441
|
+
let _tagName = null;
|
1442
|
+
let _registry = null;
|
1443
|
+
let _registered = false;
|
1444
|
+
const register = () => {
|
1445
|
+
if (_tagName === null || _registry === null || _registered) return;
|
1446
|
+
_registry.register(_tagName, CustomElement);
|
1447
|
+
_registry.register(_tagName, elementResult);
|
1448
|
+
_registered = true;
|
1449
|
+
};
|
1450
|
+
const elementResult = {
|
1451
|
+
define(tagName) {
|
1452
|
+
const registry = _registry?.scoped ? _registry.eject() : customElements;
|
1453
|
+
console.log(tagName, registry);
|
1454
|
+
if (registry.get(tagName) !== void 0) {
|
1455
|
+
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1443
1456
|
return this;
|
1444
1457
|
}
|
1445
|
-
|
1446
|
-
|
1458
|
+
registry.define(tagName, CustomElement);
|
1459
|
+
_tagName = tagName;
|
1460
|
+
register();
|
1447
1461
|
return this;
|
1448
1462
|
},
|
1449
1463
|
register(registry) {
|
1450
|
-
if (
|
1451
|
-
console.error("
|
1464
|
+
if (_tagName !== null && registry.scoped) {
|
1465
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
1452
1466
|
return this;
|
1453
1467
|
}
|
1454
|
-
registry
|
1468
|
+
_registry = registry;
|
1469
|
+
register();
|
1455
1470
|
return this;
|
1456
1471
|
},
|
1457
1472
|
eject: () => CustomElement
|
1458
1473
|
};
|
1474
|
+
return elementResult;
|
1459
1475
|
};
|
1460
|
-
var createRegistry = () => {
|
1461
|
-
const
|
1476
|
+
var createRegistry = (args) => {
|
1477
|
+
const { scoped = false } = args ?? {};
|
1478
|
+
const registryResult = /* @__PURE__ */ new Map();
|
1479
|
+
const registry = (() => {
|
1480
|
+
try {
|
1481
|
+
return new CustomElementRegistry();
|
1482
|
+
} catch (error) {
|
1483
|
+
if (scoped)
|
1484
|
+
console.error(
|
1485
|
+
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1486
|
+
);
|
1487
|
+
return customElements;
|
1488
|
+
}
|
1489
|
+
})();
|
1462
1490
|
return {
|
1463
1491
|
register: (tagName, element) => {
|
1464
|
-
if (
|
1492
|
+
if (registryResult.has(element)) {
|
1465
1493
|
console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
|
1466
1494
|
return;
|
1467
1495
|
}
|
1468
|
-
|
1496
|
+
registryResult.set(element, tagName.toUpperCase());
|
1469
1497
|
},
|
1470
|
-
getTagName: (element) =>
|
1498
|
+
getTagName: (element) => registryResult.get(element),
|
1499
|
+
eject: () => registry,
|
1500
|
+
scoped
|
1471
1501
|
};
|
1472
1502
|
};
|
1473
1503
|
export {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "thunderous",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"description": "",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/index.cjs",
|
@@ -50,5 +50,13 @@
|
|
50
50
|
},
|
51
51
|
"dependencies": {
|
52
52
|
"dompurify": "^3.2.1"
|
53
|
+
},
|
54
|
+
"peerDependenciesMeta": {
|
55
|
+
"@webcomponents/scoped-custom-element-registry": {
|
56
|
+
"optional": true
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"peerDependencies": {
|
60
|
+
"@webcomponents/scoped-custom-element-registry": "^0.0.9"
|
53
61
|
}
|
54
62
|
}
|