regor 1.6.6 → 1.6.8

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 CHANGED
@@ -262,12 +262,15 @@ createApp(appContext, template, config)
262
262
  Regor preprocesses table-related templates to keep markup valid when using
263
263
  components in table structures.
264
264
 
265
- - Supported table containers: `table`, `thead`, `tbody`, `tfoot`.
265
+ - Supported table containers: `table`, `caption`, `colgroup`, `thead`,
266
+ `tbody`, `tfoot`.
266
267
  - Component tags directly under row containers are normalized to valid hosts.
267
268
  - Component tags directly under `<tr>` are normalized to `<td>` hosts (except
268
269
  native `<td>` / `<th>`).
270
+ - Component tags directly under `<colgroup>` are normalized to `<col>` hosts
271
+ (except native `<col>`).
269
272
  - Regor preserves valid table markup while supporting component-based rows and
270
- cells in table templates.
273
+ cells, captions, sections, column groups, and columns in table templates.
271
274
 
272
275
  Example:
273
276
 
package/dist/regor.d.ts CHANGED
@@ -353,6 +353,10 @@ export type RefParam<TValueType> = Equals<TValueType, MakeRefParam<TValueType>>
353
353
  export type MakeRefParam<TValueType> = TValueType extends undefined ? never : TValueType extends Ref<infer V1> ? MakeRefParam<V1> : TValueType extends SRef<infer V2> ? MakeRefParam<V2> : TValueType extends Array<infer V3> ? Array<MakeRefParam<V3>> : TValueType extends RawTypes ? TValueType : {
354
354
  [Key in keyof TValueType]: TValueType[Key] extends Ref<infer V4> ? MakeRefParam<V4> : TValueType[Key] extends SRef<infer V5> ? MakeRefParam<V5> : MakeRefParam<TValueType[Key]>;
355
355
  };
356
+ export type RefInit<TValueType> = TValueType extends RawTypes ? never : RefInitField<TValueType>;
357
+ export type RefInitField<TValueType> = Ref<RefParam<TValueType>> | SRef<RefContent<TValueType>> | (TValueType extends undefined ? never : TValueType extends Ref<infer V1> ? Ref<RefParam<V1>> | RefInitField<V1> : TValueType extends SRef<infer V2> ? SRef<V2> | RefInitField<V2> : TValueType extends Array<infer V3> ? Array<RefInitField<V3>> : TValueType extends RawTypes ? TValueType : {
358
+ [Key in keyof TValueType]: RefInitField<TValueType[Key]>;
359
+ });
356
360
  export type SRefContent<TValueType> = Equals<TValueType, MakeSRefContent<TValueType>> extends true ? TValueType : MakeSRefContent<TValueType>;
357
361
  export type MakeSRefContent<TValueType> = TValueType extends undefined ? never : TValueType extends Ref<infer V1> ? RefContent<V1> : TValueType extends SRef<infer V2> ? V2 : TValueType extends Array<infer V3> ? V3[] : TValueType extends RawTypes ? TValueType : TValueType;
358
362
  export type UnwrapRef<TRef> = TRef extends Ref<infer V1> ? RefContent<V1> : TRef extends SRef<infer V2> ? SRefContent<V2> : TRef;
@@ -790,7 +794,7 @@ export declare const pause: <TValueType extends AnyRef>(source: TValueType) => v
790
794
  * @param value - Any value to be converted into a ref object.
791
795
  * @returns A ref object representing the input value and its nested properties.
792
796
  */
793
- export declare const ref: <TValueType>(value?: TValueType | RefContent<TValueType> | (TValueType extends Ref<infer V1> ? Ref<RefParam<V1>> : never) | (TValueType extends SRef<infer V2> ? SRef<UnwrapRef<V2>> : never) | RefParam<TValueType> | (TValueType extends Array<infer V1> ? V1[] : never) | null) => IsNull<TValueType> extends true ? Ref<unknown> : Ref<RefParam<TValueType>>;
797
+ export declare function ref<TValueType>(value?: TValueType | RefContent<TValueType> | (TValueType extends Ref<infer V1> ? Ref<RefParam<V1>> : never) | (TValueType extends SRef<infer V2> ? SRef<UnwrapRef<V2>> : never) | RefParam<TValueType> | (TValueType extends Array<infer V1> ? V1[] : never) | null): IsNull<TValueType> extends true ? Ref<unknown> : Ref<RefParam<TValueType>>;
794
798
  export declare const resume: <TValueType extends AnyRef>(source: TValueType) => void;
795
799
  /**
796
800
  * Converts the given value to an sref object and returns the sref.
@@ -816,3 +820,16 @@ export declare const trigger: <TValueType extends AnyRef>(source: TValueType, ev
816
820
  export declare const unref: <TValueType>(value: TValueType) => UnwrapRef<TValueType>;
817
821
 
818
822
  export {};
823
+
824
+ export declare function ref(value: string): Ref<string>
825
+ export declare function ref(value: number): Ref<number>
826
+ export declare function ref(value: boolean): Ref<boolean>
827
+ export declare function ref(value: bigint): Ref<bigint>
828
+ export declare function ref(value: symbol): Ref<symbol>
829
+ export declare function ref<TValueType>(
830
+ value: (TValueType extends RawTypes | readonly unknown[]
831
+ ? never
832
+ : RefInit<TValueType>) &
833
+ object,
834
+ ): IsNull<TValueType> extends true ? Ref<unknown> : Ref<RefParam<TValueType>>
835
+ export declare function ref(value: string, eventSource?: unknown): Ref<string>
@@ -4245,7 +4245,7 @@ var isDeepRef = (value) => {
4245
4245
  };
4246
4246
 
4247
4247
  // src/reactivity/ref.ts
4248
- var ref = (value) => {
4248
+ function ref(value) {
4249
4249
  if (isRaw(value)) return value;
4250
4250
  let result;
4251
4251
  if (isRef(value)) {
@@ -4276,7 +4276,7 @@ var ref = (value) => {
4276
4276
  value[key] = ref(val);
4277
4277
  }
4278
4278
  return result;
4279
- };
4279
+ }
4280
4280
 
4281
4281
  // src/app/RegorConfig.ts
4282
4282
  var _RegorConfig = class _RegorConfig {
@@ -6278,19 +6278,50 @@ var parseTagNameRange = (tagText, isClosing) => {
6278
6278
  while (i < tagText.length && (tagText[i] === " " || tagText[i] === "\n")) ++i;
6279
6279
  if (i >= tagText.length || !isNameChar(tagText[i])) return null;
6280
6280
  const start = i;
6281
- while (i < tagText.length && isNameChar(tagText[i])) ++i;
6282
- return { start, end: i };
6283
- };
6284
- var tableScopeTags = /* @__PURE__ */ new Set(["table", "thead", "tbody", "tfoot"]);
6285
- var rowParentTags = /* @__PURE__ */ new Set(["thead", "tbody", "tfoot"]);
6286
- var tableDirectAllowed = /* @__PURE__ */ new Set([
6287
- "caption",
6288
- "colgroup",
6289
- "thead",
6290
- "tbody",
6291
- "tfoot",
6292
- "tr"
6293
- ]);
6281
+ let hasUppercase = false;
6282
+ while (i < tagText.length && isNameChar(tagText[i])) {
6283
+ const c = tagText.charCodeAt(i);
6284
+ if (c >= 65 && c <= 90) {
6285
+ hasUppercase = true;
6286
+ }
6287
+ ++i;
6288
+ }
6289
+ return { start, end: i, hasUppercase };
6290
+ };
6291
+ var isTableScopeTag = (tagName) => {
6292
+ switch (tagName) {
6293
+ case "table":
6294
+ case "thead":
6295
+ case "tbody":
6296
+ case "tfoot":
6297
+ return true;
6298
+ default:
6299
+ return false;
6300
+ }
6301
+ };
6302
+ var isRowParentTag = (tagName) => {
6303
+ switch (tagName) {
6304
+ case "thead":
6305
+ case "tbody":
6306
+ case "tfoot":
6307
+ return true;
6308
+ default:
6309
+ return false;
6310
+ }
6311
+ };
6312
+ var isTableDirectAllowed = (tagName) => {
6313
+ switch (tagName) {
6314
+ case "caption":
6315
+ case "colgroup":
6316
+ case "thead":
6317
+ case "tbody":
6318
+ case "tfoot":
6319
+ case "tr":
6320
+ return true;
6321
+ default:
6322
+ return false;
6323
+ }
6324
+ };
6294
6325
  var voidElements = /* @__PURE__ */ new Set([
6295
6326
  "area",
6296
6327
  "base",
@@ -6307,12 +6338,62 @@ var voidElements = /* @__PURE__ */ new Set([
6307
6338
  "track",
6308
6339
  "wbr"
6309
6340
  ]);
6341
+ var getTableAliasHost = (tagName) => {
6342
+ switch (tagName) {
6343
+ case "caption":
6344
+ return "captionx";
6345
+ case "thead":
6346
+ return "theadx";
6347
+ case "tbody":
6348
+ return "tbodyx";
6349
+ case "tfoot":
6350
+ return "tfootx";
6351
+ case "tr":
6352
+ return "trx";
6353
+ case "td":
6354
+ return "tdx";
6355
+ case "th":
6356
+ return "thx";
6357
+ case "colgroup":
6358
+ return "colgroupx";
6359
+ case "col":
6360
+ return "colx";
6361
+ default:
6362
+ return null;
6363
+ }
6364
+ };
6365
+ var getTableAliasTag = (host) => {
6366
+ switch (host) {
6367
+ case "captionx":
6368
+ return "caption";
6369
+ case "theadx":
6370
+ return "thead";
6371
+ case "tbodyx":
6372
+ return "tbody";
6373
+ case "tfootx":
6374
+ return "tfoot";
6375
+ case "trx":
6376
+ return "tr";
6377
+ case "tdx":
6378
+ return "td";
6379
+ case "thx":
6380
+ return "th";
6381
+ case "colgroupx":
6382
+ return "colgroup";
6383
+ case "colx":
6384
+ return "col";
6385
+ default:
6386
+ return void 0;
6387
+ }
6388
+ };
6389
+ var closeTag = (tagText, tagName) => `${tagText}</${tagName}>`;
6310
6390
  var expandSelfClosingTag = (tagText, tagName) => `${tagText.slice(0, tagText.length - 2)}></${tagName}>`;
6311
6391
  var preprocess = (template) => {
6312
- var _a;
6392
+ var _a, _b;
6313
6393
  let i = 0;
6314
6394
  const out = [];
6315
6395
  const stack = [];
6396
+ const ignoredClosingTags = [];
6316
6397
  let tableScopeDepth = 0;
6317
6398
  while (i < template.length) {
6318
6399
  const lt = template.indexOf("<", i);
@@ -6351,12 +6432,21 @@ var preprocess = (template) => {
6351
6432
  continue;
6352
6433
  }
6353
6434
  const tagName = rawTag.slice(range.start, range.end);
6435
+ const nativeTagName = range.hasUppercase ? "" : tagName;
6354
6436
  if (isClosing) {
6437
+ const ignoredClosing = ignoredClosingTags[ignoredClosingTags.length - 1];
6438
+ if ((ignoredClosing == null ? void 0 : ignoredClosing.tagName) === tagName) {
6439
+ ignoredClosingTags.pop();
6440
+ if (ignoredClosing.emit) out.push(rawTag);
6441
+ i = tagEnd + 1;
6442
+ continue;
6443
+ }
6355
6444
  const top = stack[stack.length - 1];
6356
6445
  if (top) {
6357
6446
  stack.pop();
6358
6447
  out.push(top.replacementHost ? `</${top.replacementHost}>` : rawTag);
6359
- if (tableScopeTags.has(top.effectiveTag)) --tableScopeDepth;
6448
+ if (!top.isTableAlias && isTableScopeTag(top.effectiveTag))
6449
+ --tableScopeDepth;
6360
6450
  } else {
6361
6451
  out.push(rawTag);
6362
6452
  }
@@ -6367,35 +6457,47 @@ var preprocess = (template) => {
6367
6457
  const parent = stack[stack.length - 1];
6368
6458
  let replacementHost = null;
6369
6459
  if (tableScopeDepth === 0) {
6370
- if (tagName === "tr") replacementHost = "trx";
6371
- else if (tagName === "td") replacementHost = "tdx";
6372
- else if (tagName === "th") replacementHost = "thx";
6373
- } else if (rowParentTags.has((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6374
- replacementHost = tagName === "tr" ? null : "tr";
6460
+ replacementHost = getTableAliasHost(nativeTagName);
6461
+ } else if (isRowParentTag((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6462
+ replacementHost = nativeTagName === "tr" ? null : "tr";
6375
6463
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "table") {
6376
- replacementHost = tableDirectAllowed.has(tagName) ? null : "tr";
6464
+ replacementHost = isTableDirectAllowed(nativeTagName) ? null : "tr";
6377
6465
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "tr") {
6378
- replacementHost = tagName === "td" || tagName === "th" ? null : "td";
6379
- }
6380
- const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || tagName);
6466
+ replacementHost = nativeTagName === "td" || nativeTagName === "th" ? null : "td";
6467
+ } else if ((parent == null ? void 0 : parent.effectiveTag) === "colgroup") {
6468
+ replacementHost = nativeTagName === "col" ? null : "col";
6469
+ }
6470
+ const aliasTag = getTableAliasTag(replacementHost);
6471
+ const isTableAlias = aliasTag !== void 0;
6472
+ const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || nativeTagName);
6473
+ const shouldCloseVoidAlias = !!replacementHost && aliasTag === nativeTagName && voidElements.has(nativeTagName);
6474
+ const shouldIgnoreClosingTag = !selfClosing && !!replacementHost && voidElements.has(replacementHost) && !shouldCloseVoidAlias;
6475
+ const shouldIgnoreNativeVoidClosingTag = !selfClosing && !replacementHost && voidElements.has(nativeTagName);
6381
6476
  if (replacementHost) {
6382
- const isAlias = replacementHost === "trx" || replacementHost === "tdx" || replacementHost === "thx";
6383
- const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${isAlias ? `r-${tagName}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6477
+ const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${aliasTag ? `r-${aliasTag}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6384
6478
  out.push(
6385
- shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : rewrittenTag
6479
+ shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : shouldCloseVoidAlias ? closeTag(rewrittenTag, replacementHost) : rewrittenTag
6386
6480
  );
6387
6481
  } else {
6388
6482
  out.push(
6389
6483
  shouldExpandSelfClosing ? expandSelfClosingTag(rawTag, tagName) : rawTag
6390
6484
  );
6391
6485
  }
6392
- if (!selfClosing) {
6393
- const effectiveTag = replacementHost === "trx" ? "tr" : replacementHost === "tdx" ? "td" : replacementHost === "thx" ? "th" : replacementHost || tagName;
6486
+ if (shouldIgnoreClosingTag) {
6487
+ ignoredClosingTags.push({ tagName, emit: false });
6488
+ } else if (shouldCloseVoidAlias && !selfClosing) {
6489
+ ignoredClosingTags.push({ tagName, emit: false });
6490
+ } else if (shouldIgnoreNativeVoidClosingTag) {
6491
+ ignoredClosingTags.push({ tagName, emit: true });
6492
+ }
6493
+ if (!selfClosing && !shouldCloseVoidAlias && !shouldIgnoreClosingTag && !shouldIgnoreNativeVoidClosingTag && !voidElements.has(replacementHost != null ? replacementHost : nativeTagName)) {
6494
+ const effectiveTag = (_b = aliasTag != null ? aliasTag : replacementHost) != null ? _b : nativeTagName || tagName;
6394
6495
  stack.push({
6395
6496
  replacementHost,
6396
- effectiveTag
6497
+ effectiveTag,
6498
+ isTableAlias
6397
6499
  });
6398
- if (tableScopeTags.has(effectiveTag)) ++tableScopeDepth;
6500
+ if (!isTableAlias && isTableScopeTag(effectiveTag)) ++tableScopeDepth;
6399
6501
  }
6400
6502
  i = tagEnd + 1;
6401
6503
  }