@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.
@@ -910,7 +910,7 @@ const patchSlotPrepend = (HostElementPrototype) => {
910
910
  return toReturn;
911
911
  }
912
912
  if (newChild.nodeType === 1 && !!newChild.getAttribute("slot")) newChild.hidden = true;
913
- return HostElementPrototype.__prepend(newChild);
913
+ return HostElementPrototype.__prepend.call(this, newChild);
914
914
  });
915
915
  };
916
916
  };
@@ -1666,12 +1666,51 @@ const isComplexType = (o) => {
1666
1666
  return o === "object" || o === "function";
1667
1667
  };
1668
1668
  //#endregion
1669
- //#region src/runtime/signals-core.ts
1670
- const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1671
- const effect = (fn, options) => getCore().effect(fn, options);
1672
- function signal(value, options) {
1673
- return getCore().signal(value, options);
1674
- }
1669
+ //#region src/runtime/parse-property-value.ts
1670
+ /**
1671
+ * Parse a new property value for a given property type.
1672
+ *
1673
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
1674
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
1675
+ * 1. `any`, the type given to `propValue` in the function signature
1676
+ * 2. the type stored from `propType`.
1677
+ *
1678
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
1679
+ *
1680
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
1681
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
1682
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
1683
+ * ```tsx
1684
+ * <my-cmp prop-val={0}></my-cmp>
1685
+ * ```
1686
+ *
1687
+ * HTML prop values on the other hand, will always a string
1688
+ *
1689
+ * @param propValue the new value to coerce to some type
1690
+ * @param propType the type of the prop, expressed as a binary number
1691
+ * @returns the parsed/coerced value
1692
+ */
1693
+ const parsePropertyValue = (propValue, propType) => {
1694
+ if (propValue != null && !isComplexType(propValue)) {
1695
+ /**
1696
+ * ensure this value is of the correct prop type
1697
+ */
1698
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
1699
+ /**
1700
+ * force it to be a number
1701
+ */
1702
+ if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
1703
+ /**
1704
+ * could have been passed as a number or boolean but we still want it as a string
1705
+ */
1706
+ if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
1707
+ return propValue;
1708
+ }
1709
+ /**
1710
+ * not sure exactly what type we want so no need to change to a different type
1711
+ */
1712
+ return propValue;
1713
+ };
1675
1714
  //#endregion
1676
1715
  //#region src/runtime/event-emitter.ts
1677
1716
  const createEvent = (ref, name, flags) => {
@@ -3078,6 +3117,124 @@ const serverSideConnected = (elm) => {
3078
3117
  }
3079
3118
  };
3080
3119
  //#endregion
3120
+ //#region src/runtime/set-value.ts
3121
+ /**
3122
+ * The value a reflected prop writes to its attribute: the serialized value if it has one.
3123
+ * @param hostRef the component's host ref
3124
+ * @param propName the prop
3125
+ * @param val the prop's value
3126
+ * @returns the value to reflect
3127
+ */
3128
+ const getReflectedValue = (hostRef, propName, val) => BUILD.serializer && hostRef.$serializerValues$.has(propName) ? hostRef.$serializerValues$.get(propName) : val;
3129
+ /**
3130
+ * Write a reflected prop's attribute as soon as the prop changes, like native elements do,
3131
+ * so it agrees with the prop before watchers run. Until the first render, rendering reflects it.
3132
+ * @param hostRef the component's host ref
3133
+ * @param cmpMeta the component's runtime metadata
3134
+ * @param elm the host element
3135
+ * @param propName the prop that changed
3136
+ * @param oldAttrVal the previously reflected value
3137
+ * @param newAttrVal the value to reflect
3138
+ */
3139
+ const reflectProp = (hostRef, cmpMeta, elm, propName, oldAttrVal, newAttrVal) => {
3140
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasRendered) || !(cmpMeta.$members$[propName][0] & MEMBER_FLAGS.ReflectAttr)) return;
3141
+ const attrName = cmpMeta.$attrsToReflect$?.find(([p]) => p === propName)?.[1];
3142
+ if (!attrName) return;
3143
+ if (BUILD.serializer) hostRef.$flags$ |= HOST_FLAGS.isReflecting;
3144
+ setAccessor(elm, attrName, oldAttrVal, newAttrVal, false, VNODE_FLAGS.isHost);
3145
+ if (BUILD.serializer) hostRef.$flags$ &= ~HOST_FLAGS.isReflecting;
3146
+ };
3147
+ const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
3148
+ const run = (inst) => {
3149
+ let attrVal = val;
3150
+ for (const serializer of cmpMeta.$serializers$[propName]) {
3151
+ const [[methodName]] = Object.entries(serializer);
3152
+ attrVal = inst[methodName](attrVal, propName);
3153
+ }
3154
+ hostRef.$serializerValues$.set(propName, attrVal);
3155
+ };
3156
+ if (instance) run(instance);
3157
+ else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
3158
+ };
3159
+ const getValue = (ref, propName) => {
3160
+ if (BUILD.signalBacking) {
3161
+ const sig = getHostRef(ref)?.$signalValues$?.get(propName);
3162
+ if (sig !== void 0) return sig.value;
3163
+ }
3164
+ return getHostRef(ref).$instanceValues$.get(propName);
3165
+ };
3166
+ const setValue = (ref, propName, newVal, cmpMeta) => {
3167
+ const hostRef = getHostRef(ref);
3168
+ if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
3169
+ if (BUILD.signalBacking) {
3170
+ const sig = hostRef?.$signalValues$?.get(propName);
3171
+ if (sig !== void 0) {
3172
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3173
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
3174
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3175
+ applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
3176
+ }
3177
+ if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
3178
+ return;
3179
+ }
3180
+ }
3181
+ if (!hostRef) {
3182
+ 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$}"`);
3183
+ return;
3184
+ }
3185
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3186
+ const oldVal = hostRef.$instanceValues$.get(propName);
3187
+ const flags = hostRef.$flags$;
3188
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
3189
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3190
+ const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
3191
+ if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
3192
+ hostRef.$instanceValues$.set(propName, newVal);
3193
+ const oldAttrVal = BUILD.reflect && getReflectedValue(hostRef, propName, oldVal);
3194
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
3195
+ if (BUILD.reflect) reflectProp(hostRef, cmpMeta, elm, propName, oldAttrVal, getReflectedValue(hostRef, propName, newVal));
3196
+ if (BUILD.isDev) {
3197
+ 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);
3198
+ 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);
3199
+ }
3200
+ if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
3201
+ const watchMethods = cmpMeta.$watchers$[propName];
3202
+ if (watchMethods) watchMethods.map((watcher) => {
3203
+ try {
3204
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
3205
+ if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
3206
+ if (BUILD.signalBacking && !hostRef.$signalValues$) return;
3207
+ if (!instance) hostRef.$fetchedCbList$.push(() => {
3208
+ hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
3209
+ });
3210
+ else instance[watchMethodName](newVal, oldVal, propName);
3211
+ }
3212
+ } catch (e) {
3213
+ consoleError(e, elm);
3214
+ }
3215
+ });
3216
+ }
3217
+ if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
3218
+ if (instance.componentShouldUpdate) {
3219
+ const changes = hostRef.$queuedPropChanges$ ||= {};
3220
+ changes[propName] = {
3221
+ newVal,
3222
+ oldVal: changes[propName]?.oldVal ?? oldVal
3223
+ };
3224
+ }
3225
+ if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3226
+ }
3227
+ }
3228
+ };
3229
+ //#endregion
3230
+ //#region src/runtime/signals-core.ts
3231
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
3232
+ const effect = (fn, options) => getCore().effect(fn, options);
3233
+ const untracked = (fn) => getCore().untracked(fn);
3234
+ function signal(value, options) {
3235
+ return getCore().signal(value, options);
3236
+ }
3237
+ //#endregion
3081
3238
  //#region src/runtime/signals.ts
3082
3239
  const STENCIL_SIGNALS_SYMBOL = Symbol.for("stencil.signals");
3083
3240
  /**
@@ -3122,6 +3279,14 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
3122
3279
  }
3123
3280
  prevScheduleVal = newVal;
3124
3281
  }));
3282
+ if (BUILD.reflect && memberFlags & MEMBER_FLAGS.ReflectAttr) {
3283
+ let prevAttrVal = getReflectedValue(hostRef, memberName, sig.peek());
3284
+ disposers.push(effect(() => {
3285
+ const attrVal = getReflectedValue(hostRef, memberName, sig.value);
3286
+ untracked(() => reflectProp(hostRef, cmpMeta, elm, memberName, prevAttrVal, attrVal));
3287
+ prevAttrVal = attrVal;
3288
+ }));
3289
+ }
3125
3290
  if (BUILD.propChangeCallback && cmpMeta.$watchers$?.[memberName]) {
3126
3291
  const watchMethods = cmpMeta.$watchers$[memberName];
3127
3292
  let prevWatchVal = sig.peek();
@@ -3190,7 +3355,7 @@ const initializeEffects = (elm, hostRef) => {
3190
3355
  * Modified for Stencil's compiler and vdom
3191
3356
  */
3192
3357
  const h = (nodeName, vnodeData, ...children) => {
3193
- if (typeof nodeName === "string") nodeName = transformTag(nodeName);
3358
+ if (typeof nodeName === "string" && nodeName.includes("-")) nodeName = transformTag(nodeName);
3194
3359
  let child = null;
3195
3360
  let key = null;
3196
3361
  let slotName = null;
@@ -3664,7 +3829,7 @@ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) =
3664
3829
  if (!slottedNode || slottedNode.nodeValue?.startsWith("s.")) return;
3665
3830
  do {
3666
3831
  const sa = slottedNode["getAttribute"] && slottedNode.getAttribute("slot");
3667
- if ((sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3832
+ 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)) {
3668
3833
  slottedNode["s-sn"] = slotName;
3669
3834
  group.push({
3670
3835
  slot: slotNode,
@@ -4186,134 +4351,6 @@ const normalizeWatchers = (raw) => {
4186
4351
  return out;
4187
4352
  };
4188
4353
  //#endregion
4189
- //#region src/runtime/parse-property-value.ts
4190
- /**
4191
- * Parse a new property value for a given property type.
4192
- *
4193
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
4194
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
4195
- * 1. `any`, the type given to `propValue` in the function signature
4196
- * 2. the type stored from `propType`.
4197
- *
4198
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
4199
- *
4200
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
4201
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
4202
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
4203
- * ```tsx
4204
- * <my-cmp prop-val={0}></my-cmp>
4205
- * ```
4206
- *
4207
- * HTML prop values on the other hand, will always a string
4208
- *
4209
- * @param propValue the new value to coerce to some type
4210
- * @param propType the type of the prop, expressed as a binary number
4211
- * @returns the parsed/coerced value
4212
- */
4213
- const parsePropertyValue = (propValue, propType) => {
4214
- if (propValue != null && !isComplexType(propValue)) {
4215
- /**
4216
- * ensure this value is of the correct prop type
4217
- */
4218
- if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
4219
- /**
4220
- * force it to be a number
4221
- */
4222
- if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
4223
- /**
4224
- * could have been passed as a number or boolean but we still want it as a string
4225
- */
4226
- if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
4227
- return propValue;
4228
- }
4229
- /**
4230
- * not sure exactly what type we want so no need to change to a different type
4231
- */
4232
- return propValue;
4233
- };
4234
- //#endregion
4235
- //#region src/runtime/set-value.ts
4236
- const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
4237
- const run = (inst) => {
4238
- let attrVal = val;
4239
- for (const serializer of cmpMeta.$serializers$[propName]) {
4240
- const [[methodName]] = Object.entries(serializer);
4241
- attrVal = inst[methodName](attrVal, propName);
4242
- }
4243
- hostRef.$serializerValues$.set(propName, attrVal);
4244
- };
4245
- if (instance) run(instance);
4246
- else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
4247
- };
4248
- const getValue = (ref, propName) => {
4249
- if (BUILD.signalBacking) {
4250
- const sig = getHostRef(ref)?.$signalValues$?.get(propName);
4251
- if (sig !== void 0) return sig.value;
4252
- }
4253
- return getHostRef(ref).$instanceValues$.get(propName);
4254
- };
4255
- const setValue = (ref, propName, newVal, cmpMeta) => {
4256
- const hostRef = getHostRef(ref);
4257
- if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
4258
- if (BUILD.signalBacking) {
4259
- const sig = hostRef?.$signalValues$?.get(propName);
4260
- if (sig !== void 0) {
4261
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4262
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
4263
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4264
- applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
4265
- }
4266
- if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
4267
- return;
4268
- }
4269
- }
4270
- if (!hostRef) {
4271
- 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$}"`);
4272
- return;
4273
- }
4274
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4275
- const oldVal = hostRef.$instanceValues$.get(propName);
4276
- const flags = hostRef.$flags$;
4277
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
4278
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4279
- const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
4280
- if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
4281
- hostRef.$instanceValues$.set(propName, newVal);
4282
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
4283
- if (BUILD.isDev) {
4284
- 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);
4285
- 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);
4286
- }
4287
- if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
4288
- const watchMethods = cmpMeta.$watchers$[propName];
4289
- if (watchMethods) watchMethods.map((watcher) => {
4290
- try {
4291
- const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4292
- if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
4293
- if (BUILD.signalBacking && !hostRef.$signalValues$) return;
4294
- if (!instance) hostRef.$fetchedCbList$.push(() => {
4295
- hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
4296
- });
4297
- else instance[watchMethodName](newVal, oldVal, propName);
4298
- }
4299
- } catch (e) {
4300
- consoleError(e, elm);
4301
- }
4302
- });
4303
- }
4304
- if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
4305
- if (instance.componentShouldUpdate) {
4306
- const changes = hostRef.$queuedPropChanges$ ||= {};
4307
- changes[propName] = {
4308
- newVal,
4309
- oldVal: changes[propName]?.oldVal ?? oldVal
4310
- };
4311
- }
4312
- if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
4313
- }
4314
- }
4315
- };
4316
- //#endregion
4317
4354
  //#region src/runtime/proxy-component.ts
4318
4355
  /**
4319
4356
  * Serialize a prop value the way `setAccessor()` does when it reflects it, so the runtime can