@stencil/core 5.0.0-rc.8 → 5.0.0-rc.9

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.
@@ -1044,7 +1044,7 @@ const patchSlotPrepend = (HostElementPrototype) => {
1044
1044
  return toReturn;
1045
1045
  }
1046
1046
  if (newChild.nodeType === 1 && !!newChild.getAttribute("slot")) newChild.hidden = true;
1047
- return HostElementPrototype.__prepend(newChild);
1047
+ return HostElementPrototype.__prepend.call(this, newChild);
1048
1048
  });
1049
1049
  };
1050
1050
  };
@@ -1800,12 +1800,51 @@ const isComplexType = (o) => {
1800
1800
  return o === "object" || o === "function";
1801
1801
  };
1802
1802
  //#endregion
1803
- //#region src/runtime/signals-core.ts
1804
- const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1805
- const effect = (fn, options) => getCore().effect(fn, options);
1806
- function signal(value, options) {
1807
- return getCore().signal(value, options);
1808
- }
1803
+ //#region src/runtime/parse-property-value.ts
1804
+ /**
1805
+ * Parse a new property value for a given property type.
1806
+ *
1807
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
1808
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
1809
+ * 1. `any`, the type given to `propValue` in the function signature
1810
+ * 2. the type stored from `propType`.
1811
+ *
1812
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
1813
+ *
1814
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
1815
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
1816
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
1817
+ * ```tsx
1818
+ * <my-cmp prop-val={0}></my-cmp>
1819
+ * ```
1820
+ *
1821
+ * HTML prop values on the other hand, will always a string
1822
+ *
1823
+ * @param propValue the new value to coerce to some type
1824
+ * @param propType the type of the prop, expressed as a binary number
1825
+ * @returns the parsed/coerced value
1826
+ */
1827
+ const parsePropertyValue = (propValue, propType) => {
1828
+ if (propValue != null && !isComplexType(propValue)) {
1829
+ /**
1830
+ * ensure this value is of the correct prop type
1831
+ */
1832
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
1833
+ /**
1834
+ * force it to be a number
1835
+ */
1836
+ if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
1837
+ /**
1838
+ * could have been passed as a number or boolean but we still want it as a string
1839
+ */
1840
+ if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
1841
+ return propValue;
1842
+ }
1843
+ /**
1844
+ * not sure exactly what type we want so no need to change to a different type
1845
+ */
1846
+ return propValue;
1847
+ };
1809
1848
  //#endregion
1810
1849
  //#region src/runtime/event-emitter.ts
1811
1850
  const createEvent = (ref, name, flags) => {
@@ -3212,6 +3251,124 @@ const serverSideConnected = (elm) => {
3212
3251
  }
3213
3252
  };
3214
3253
  //#endregion
3254
+ //#region src/runtime/set-value.ts
3255
+ /**
3256
+ * The value a reflected prop writes to its attribute: the serialized value if it has one.
3257
+ * @param hostRef the component's host ref
3258
+ * @param propName the prop
3259
+ * @param val the prop's value
3260
+ * @returns the value to reflect
3261
+ */
3262
+ const getReflectedValue = (hostRef, propName, val) => BUILD.serializer && hostRef.$serializerValues$.has(propName) ? hostRef.$serializerValues$.get(propName) : val;
3263
+ /**
3264
+ * Write a reflected prop's attribute as soon as the prop changes, like native elements do,
3265
+ * so it agrees with the prop before watchers run. Until the first render, rendering reflects it.
3266
+ * @param hostRef the component's host ref
3267
+ * @param cmpMeta the component's runtime metadata
3268
+ * @param elm the host element
3269
+ * @param propName the prop that changed
3270
+ * @param oldAttrVal the previously reflected value
3271
+ * @param newAttrVal the value to reflect
3272
+ */
3273
+ const reflectProp = (hostRef, cmpMeta, elm, propName, oldAttrVal, newAttrVal) => {
3274
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasRendered) || !(cmpMeta.$members$[propName][0] & MEMBER_FLAGS.ReflectAttr)) return;
3275
+ const attrName = cmpMeta.$attrsToReflect$?.find(([p]) => p === propName)?.[1];
3276
+ if (!attrName) return;
3277
+ if (BUILD.serializer) hostRef.$flags$ |= HOST_FLAGS.isReflecting;
3278
+ setAccessor(elm, attrName, oldAttrVal, newAttrVal, false, VNODE_FLAGS.isHost);
3279
+ if (BUILD.serializer) hostRef.$flags$ &= ~HOST_FLAGS.isReflecting;
3280
+ };
3281
+ const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
3282
+ const run = (inst) => {
3283
+ let attrVal = val;
3284
+ for (const serializer of cmpMeta.$serializers$[propName]) {
3285
+ const [[methodName]] = Object.entries(serializer);
3286
+ attrVal = inst[methodName](attrVal, propName);
3287
+ }
3288
+ hostRef.$serializerValues$.set(propName, attrVal);
3289
+ };
3290
+ if (instance) run(instance);
3291
+ else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
3292
+ };
3293
+ const getValue = (ref, propName) => {
3294
+ if (BUILD.signalBacking) {
3295
+ const sig = getHostRef(ref)?.$signalValues$?.get(propName);
3296
+ if (sig !== void 0) return sig.value;
3297
+ }
3298
+ return getHostRef(ref).$instanceValues$.get(propName);
3299
+ };
3300
+ const setValue = (ref, propName, newVal, cmpMeta) => {
3301
+ const hostRef = getHostRef(ref);
3302
+ if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
3303
+ if (BUILD.signalBacking) {
3304
+ const sig = hostRef?.$signalValues$?.get(propName);
3305
+ if (sig !== void 0) {
3306
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3307
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
3308
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3309
+ applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
3310
+ }
3311
+ if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
3312
+ return;
3313
+ }
3314
+ }
3315
+ if (!hostRef) {
3316
+ if (BUILD.lazyLoad) throw new Error(BUILD.isDev ? `Couldn't find host element for "${cmpMeta.$tagName$}". This usually happens when integrating a 3rd party Stencil component with another Stencil runtime. See https://github.com/stenciljs/core/issues/5457` : `Host element not found for "${cmpMeta.$tagName$}"`);
3317
+ return;
3318
+ }
3319
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3320
+ const oldVal = hostRef.$instanceValues$.get(propName);
3321
+ const flags = hostRef.$flags$;
3322
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
3323
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3324
+ const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
3325
+ if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
3326
+ hostRef.$instanceValues$.set(propName, newVal);
3327
+ const oldAttrVal = BUILD.reflect && getReflectedValue(hostRef, propName, oldVal);
3328
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
3329
+ if (BUILD.reflect) reflectProp(hostRef, cmpMeta, elm, propName, oldAttrVal, getReflectedValue(hostRef, propName, newVal));
3330
+ if (BUILD.isDev) {
3331
+ if (hostRef.$flags$ & HOST_FLAGS.devOnRender) consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3332
+ else if (hostRef.$flags$ & HOST_FLAGS.devOnDidLoad) consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3333
+ }
3334
+ if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
3335
+ const watchMethods = cmpMeta.$watchers$[propName];
3336
+ if (watchMethods) watchMethods.map((watcher) => {
3337
+ try {
3338
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
3339
+ if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
3340
+ if (BUILD.signalBacking && !hostRef.$signalValues$) return;
3341
+ if (!instance) hostRef.$fetchedCbList$.push(() => {
3342
+ hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
3343
+ });
3344
+ else instance[watchMethodName](newVal, oldVal, propName);
3345
+ }
3346
+ } catch (e) {
3347
+ consoleError(e, elm);
3348
+ }
3349
+ });
3350
+ }
3351
+ if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
3352
+ if (instance.componentShouldUpdate) {
3353
+ const changes = hostRef.$queuedPropChanges$ ||= {};
3354
+ changes[propName] = {
3355
+ newVal,
3356
+ oldVal: changes[propName]?.oldVal ?? oldVal
3357
+ };
3358
+ }
3359
+ if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3360
+ }
3361
+ }
3362
+ };
3363
+ //#endregion
3364
+ //#region src/runtime/signals-core.ts
3365
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
3366
+ const effect = (fn, options) => getCore().effect(fn, options);
3367
+ const untracked = (fn) => getCore().untracked(fn);
3368
+ function signal(value, options) {
3369
+ return getCore().signal(value, options);
3370
+ }
3371
+ //#endregion
3215
3372
  //#region src/runtime/signals.ts
3216
3373
  const STENCIL_SIGNALS_SYMBOL = Symbol.for("stencil.signals");
3217
3374
  /**
@@ -3256,6 +3413,14 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
3256
3413
  }
3257
3414
  prevScheduleVal = newVal;
3258
3415
  }));
3416
+ if (BUILD.reflect && memberFlags & MEMBER_FLAGS.ReflectAttr) {
3417
+ let prevAttrVal = getReflectedValue(hostRef, memberName, sig.peek());
3418
+ disposers.push(effect(() => {
3419
+ const attrVal = getReflectedValue(hostRef, memberName, sig.value);
3420
+ untracked(() => reflectProp(hostRef, cmpMeta, elm, memberName, prevAttrVal, attrVal));
3421
+ prevAttrVal = attrVal;
3422
+ }));
3423
+ }
3259
3424
  if (BUILD.propChangeCallback && cmpMeta.$watchers$?.[memberName]) {
3260
3425
  const watchMethods = cmpMeta.$watchers$[memberName];
3261
3426
  let prevWatchVal = sig.peek();
@@ -3324,7 +3489,7 @@ const initializeEffects = (elm, hostRef) => {
3324
3489
  * Modified for Stencil's compiler and vdom
3325
3490
  */
3326
3491
  const h = (nodeName, vnodeData, ...children) => {
3327
- if (typeof nodeName === "string") nodeName = transformTag(nodeName);
3492
+ if (typeof nodeName === "string" && nodeName.includes("-")) nodeName = transformTag(nodeName);
3328
3493
  let child = null;
3329
3494
  let key = null;
3330
3495
  let slotName = null;
@@ -3798,7 +3963,7 @@ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) =
3798
3963
  if (!slottedNode || slottedNode.nodeValue?.startsWith("s.")) return;
3799
3964
  do {
3800
3965
  const sa = slottedNode["getAttribute"] && slottedNode.getAttribute("slot");
3801
- if ((sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3966
+ if ((slottedNode["getAttribute"] && slottedNode.getAttribute("s-sn")) === slotName || (sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3802
3967
  slottedNode["s-sn"] = slotName;
3803
3968
  group.push({
3804
3969
  slot: slotNode,
@@ -4320,134 +4485,6 @@ const normalizeWatchers = (raw) => {
4320
4485
  return out;
4321
4486
  };
4322
4487
  //#endregion
4323
- //#region src/runtime/parse-property-value.ts
4324
- /**
4325
- * Parse a new property value for a given property type.
4326
- *
4327
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
4328
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
4329
- * 1. `any`, the type given to `propValue` in the function signature
4330
- * 2. the type stored from `propType`.
4331
- *
4332
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
4333
- *
4334
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
4335
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
4336
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
4337
- * ```tsx
4338
- * <my-cmp prop-val={0}></my-cmp>
4339
- * ```
4340
- *
4341
- * HTML prop values on the other hand, will always a string
4342
- *
4343
- * @param propValue the new value to coerce to some type
4344
- * @param propType the type of the prop, expressed as a binary number
4345
- * @returns the parsed/coerced value
4346
- */
4347
- const parsePropertyValue = (propValue, propType) => {
4348
- if (propValue != null && !isComplexType(propValue)) {
4349
- /**
4350
- * ensure this value is of the correct prop type
4351
- */
4352
- if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
4353
- /**
4354
- * force it to be a number
4355
- */
4356
- if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
4357
- /**
4358
- * could have been passed as a number or boolean but we still want it as a string
4359
- */
4360
- if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
4361
- return propValue;
4362
- }
4363
- /**
4364
- * not sure exactly what type we want so no need to change to a different type
4365
- */
4366
- return propValue;
4367
- };
4368
- //#endregion
4369
- //#region src/runtime/set-value.ts
4370
- const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
4371
- const run = (inst) => {
4372
- let attrVal = val;
4373
- for (const serializer of cmpMeta.$serializers$[propName]) {
4374
- const [[methodName]] = Object.entries(serializer);
4375
- attrVal = inst[methodName](attrVal, propName);
4376
- }
4377
- hostRef.$serializerValues$.set(propName, attrVal);
4378
- };
4379
- if (instance) run(instance);
4380
- else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
4381
- };
4382
- const getValue = (ref, propName) => {
4383
- if (BUILD.signalBacking) {
4384
- const sig = getHostRef(ref)?.$signalValues$?.get(propName);
4385
- if (sig !== void 0) return sig.value;
4386
- }
4387
- return getHostRef(ref).$instanceValues$.get(propName);
4388
- };
4389
- const setValue = (ref, propName, newVal, cmpMeta) => {
4390
- const hostRef = getHostRef(ref);
4391
- if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
4392
- if (BUILD.signalBacking) {
4393
- const sig = hostRef?.$signalValues$?.get(propName);
4394
- if (sig !== void 0) {
4395
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4396
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
4397
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4398
- applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
4399
- }
4400
- if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
4401
- return;
4402
- }
4403
- }
4404
- if (!hostRef) {
4405
- if (BUILD.lazyLoad) throw new Error(BUILD.isDev ? `Couldn't find host element for "${cmpMeta.$tagName$}". This usually happens when integrating a 3rd party Stencil component with another Stencil runtime. See https://github.com/stenciljs/core/issues/5457` : `Host element not found for "${cmpMeta.$tagName$}"`);
4406
- return;
4407
- }
4408
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4409
- const oldVal = hostRef.$instanceValues$.get(propName);
4410
- const flags = hostRef.$flags$;
4411
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
4412
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4413
- const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
4414
- if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
4415
- hostRef.$instanceValues$.set(propName, newVal);
4416
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
4417
- if (BUILD.isDev) {
4418
- if (hostRef.$flags$ & HOST_FLAGS.devOnRender) consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
4419
- else if (hostRef.$flags$ & HOST_FLAGS.devOnDidLoad) consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
4420
- }
4421
- if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
4422
- const watchMethods = cmpMeta.$watchers$[propName];
4423
- if (watchMethods) watchMethods.map((watcher) => {
4424
- try {
4425
- const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4426
- if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
4427
- if (BUILD.signalBacking && !hostRef.$signalValues$) return;
4428
- if (!instance) hostRef.$fetchedCbList$.push(() => {
4429
- hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
4430
- });
4431
- else instance[watchMethodName](newVal, oldVal, propName);
4432
- }
4433
- } catch (e) {
4434
- consoleError(e, elm);
4435
- }
4436
- });
4437
- }
4438
- if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
4439
- if (instance.componentShouldUpdate) {
4440
- const changes = hostRef.$queuedPropChanges$ ||= {};
4441
- changes[propName] = {
4442
- newVal,
4443
- oldVal: changes[propName]?.oldVal ?? oldVal
4444
- };
4445
- }
4446
- if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
4447
- }
4448
- }
4449
- };
4450
- //#endregion
4451
4488
  //#region src/runtime/proxy-component.ts
4452
4489
  /**
4453
4490
  * Serialize a prop value the way `setAccessor()` does when it reflects it, so the runtime can