@wildwinter/app-shell 0.28.0 → 0.30.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.d.cts CHANGED
@@ -339,6 +339,76 @@ declare function gameIdify(text: string): string;
339
339
  * "derive one", which is a different thing from an address. */
340
340
  declare function isValidGameId(gameId: string): boolean;
341
341
 
342
+ /** The five words `@wildwinter/expr` lexes as keywords, so a property may not be
343
+ * called any of them: the reference does not resolve, it fails to parse. Kept
344
+ * here as a copy for the same reason the rules are (no dependency), and each
345
+ * app probes the real parser to prove the list is still true. */
346
+ declare const RESERVED_PROPERTY_NAMES: readonly string[];
347
+ /** What an editor should tell an author, in one line. */
348
+ declare const PROPERTY_NAME_HINT = "Lower case letters, digits and underscores. Cannot start with a digit. No hyphens or spaces.";
349
+ /**
350
+ * Coerce a label into a legal property name: lower case, apostrophes dropped,
351
+ * runs of anything else to a single underscore, no trailing underscore, an
352
+ * underscore in front if it would otherwise start with a digit, and one behind
353
+ * if it would otherwise be a keyword.
354
+ *
355
+ * A LEADING underscore is kept where the author typed one, because `_private` is
356
+ * a legal name and a meaningful choice; only the ends that would be illegal are
357
+ * touched.
358
+ *
359
+ * May return "", when there was nothing usable in the input. Callers treat that
360
+ * as "no name yet" rather than as a name.
361
+ */
362
+ declare function propertyNameify(text: string): string;
363
+ /**
364
+ * Is this a name the expression language can actually reach? Lower case letters,
365
+ * digits and underscores, not starting with a digit, and not a keyword.
366
+ *
367
+ * "" is NOT legal: an unnamed declaration is an unfinished row, which is a
368
+ * different thing from an illegal one, and callers distinguish them.
369
+ */
370
+ declare function isValidPropertyName(name: string): boolean;
371
+ /**
372
+ * The one thing that is only a case difference, e.g. `isNight` -> `isnight`.
373
+ *
374
+ * Worth its own question because it is the only violation that can be repaired
375
+ * without guessing at intent: the language already folds every REFERENCE, so
376
+ * folding the declaration to match changes nothing observable, where inventing
377
+ * an underscore for a space is a decision about what the author meant. Loaders
378
+ * fold this class silently and report the rest.
379
+ */
380
+ declare function isCaseOnlyPropertyName(name: string): boolean;
381
+
382
+ /**
383
+ * One line saying what is wrong with this name, or undefined when nothing is.
384
+ *
385
+ * Each branch names what actually HAPPENS rather than reciting the rule, because
386
+ * the person reading it is usually somebody wondering why a condition does
387
+ * nothing. Kept to one line: it lands in a rollover on the field, and hosts
388
+ * repeat it in the Save error rather than inventing a summary of their own.
389
+ */
390
+ declare function propertyNameProblem(name: string): string | undefined;
391
+ /**
392
+ * Wire a name field: mark it live, explain the fault in its rollover, and coerce
393
+ * on Tab. `onCommit` receives what the author typed, VERBATIM, on every input.
394
+ *
395
+ * `.illegal` rather than dupGuard's `.invalid`, because both can be true of one
396
+ * field and `dupGuard.check()` owns that class: it would clear this marking every
397
+ * time it ran, including at the moment of a blocked Save.
398
+ *
399
+ * An empty field is not marked. An unfinished row is a different thing from an
400
+ * illegal one, and hosts prune blank names on save.
401
+ */
402
+ declare function bindPropertyName(input: HTMLInputElement, onCommit: (value: string) => void, opts?: {
403
+ hint?: string;
404
+ }): void;
405
+ /**
406
+ * The first field in `host` holding a name no expression could reach, for a Save
407
+ * gate. Hosts hand this back beside `dupGuard.firstDuplicate()`: two faults, two
408
+ * sets of words, one gate.
409
+ */
410
+ declare function firstIllegalPropertyName(host: ParentNode): HTMLInputElement | null;
411
+
342
412
  interface GameIdEditorOptions {
343
413
  anchor: HTMLElement;
344
414
  /** The pinned address, or "" when it is being derived. */
@@ -719,4 +789,4 @@ interface StepperBarOptions {
719
789
  /** Draw (or hide) the bar in `host`. Idempotent: call it again with new state. */
720
790
  declare function renderStepperBar(host: HTMLElement, opts: StepperBarOptions): void;
721
791
 
722
- export { type AboutOptions, type AnchoredPanel, type AnchoredPanelOptions, type Child, type Comment, type CommentMessage, type CommentsOptions, type ConfirmOptions, type DocLine, type DupGuard, type ElProps, type GameIdEditorOptions, type IconName, type IconSvgName, type Identity, type IdentityOptions, type JobProgressOptions, type JobProgressView, type Notes, type NotesEditorOptions, PALETTE, PALETTE_SIZE, type PaneShell, type PaneShellOptions, type PaneShellState, type PaneSide, type PaneSideConfig, type PinButton, type PinButtonOptions, type SaveController, type SaveControllerOptions, type SaveIndicator, type SaveStatus, type SettingsDialog, type SettingsDialogOptions, type SettingsSection, type SettingsSectionHandle, type ShardVc, type StaleBarOptions, type StepperBarOptions, type StepperItem, type StepperTone, type TipRect, type TooltipOptions, type VcMap, askIdentity, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isValidGameId, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
792
+ export { type AboutOptions, type AnchoredPanel, type AnchoredPanelOptions, type Child, type Comment, type CommentMessage, type CommentsOptions, type ConfirmOptions, type DocLine, type DupGuard, type ElProps, type GameIdEditorOptions, type IconName, type IconSvgName, type Identity, type IdentityOptions, type JobProgressOptions, type JobProgressView, type Notes, type NotesEditorOptions, PALETTE, PALETTE_SIZE, PROPERTY_NAME_HINT, type PaneShell, type PaneShellOptions, type PaneShellState, type PaneSide, type PaneSideConfig, type PinButton, type PinButtonOptions, RESERVED_PROPERTY_NAMES, type SaveController, type SaveControllerOptions, type SaveIndicator, type SaveStatus, type SettingsDialog, type SettingsDialogOptions, type SettingsSection, type SettingsSectionHandle, type ShardVc, type StaleBarOptions, type StepperBarOptions, type StepperItem, type StepperTone, type TipRect, type TooltipOptions, type VcMap, askIdentity, bindPropertyName, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, firstIllegalPropertyName, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isCaseOnlyPropertyName, isValidGameId, isValidPropertyName, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, propertyNameProblem, propertyNameify, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
package/dist/index.d.ts CHANGED
@@ -339,6 +339,76 @@ declare function gameIdify(text: string): string;
339
339
  * "derive one", which is a different thing from an address. */
340
340
  declare function isValidGameId(gameId: string): boolean;
341
341
 
342
+ /** The five words `@wildwinter/expr` lexes as keywords, so a property may not be
343
+ * called any of them: the reference does not resolve, it fails to parse. Kept
344
+ * here as a copy for the same reason the rules are (no dependency), and each
345
+ * app probes the real parser to prove the list is still true. */
346
+ declare const RESERVED_PROPERTY_NAMES: readonly string[];
347
+ /** What an editor should tell an author, in one line. */
348
+ declare const PROPERTY_NAME_HINT = "Lower case letters, digits and underscores. Cannot start with a digit. No hyphens or spaces.";
349
+ /**
350
+ * Coerce a label into a legal property name: lower case, apostrophes dropped,
351
+ * runs of anything else to a single underscore, no trailing underscore, an
352
+ * underscore in front if it would otherwise start with a digit, and one behind
353
+ * if it would otherwise be a keyword.
354
+ *
355
+ * A LEADING underscore is kept where the author typed one, because `_private` is
356
+ * a legal name and a meaningful choice; only the ends that would be illegal are
357
+ * touched.
358
+ *
359
+ * May return "", when there was nothing usable in the input. Callers treat that
360
+ * as "no name yet" rather than as a name.
361
+ */
362
+ declare function propertyNameify(text: string): string;
363
+ /**
364
+ * Is this a name the expression language can actually reach? Lower case letters,
365
+ * digits and underscores, not starting with a digit, and not a keyword.
366
+ *
367
+ * "" is NOT legal: an unnamed declaration is an unfinished row, which is a
368
+ * different thing from an illegal one, and callers distinguish them.
369
+ */
370
+ declare function isValidPropertyName(name: string): boolean;
371
+ /**
372
+ * The one thing that is only a case difference, e.g. `isNight` -> `isnight`.
373
+ *
374
+ * Worth its own question because it is the only violation that can be repaired
375
+ * without guessing at intent: the language already folds every REFERENCE, so
376
+ * folding the declaration to match changes nothing observable, where inventing
377
+ * an underscore for a space is a decision about what the author meant. Loaders
378
+ * fold this class silently and report the rest.
379
+ */
380
+ declare function isCaseOnlyPropertyName(name: string): boolean;
381
+
382
+ /**
383
+ * One line saying what is wrong with this name, or undefined when nothing is.
384
+ *
385
+ * Each branch names what actually HAPPENS rather than reciting the rule, because
386
+ * the person reading it is usually somebody wondering why a condition does
387
+ * nothing. Kept to one line: it lands in a rollover on the field, and hosts
388
+ * repeat it in the Save error rather than inventing a summary of their own.
389
+ */
390
+ declare function propertyNameProblem(name: string): string | undefined;
391
+ /**
392
+ * Wire a name field: mark it live, explain the fault in its rollover, and coerce
393
+ * on Tab. `onCommit` receives what the author typed, VERBATIM, on every input.
394
+ *
395
+ * `.illegal` rather than dupGuard's `.invalid`, because both can be true of one
396
+ * field and `dupGuard.check()` owns that class: it would clear this marking every
397
+ * time it ran, including at the moment of a blocked Save.
398
+ *
399
+ * An empty field is not marked. An unfinished row is a different thing from an
400
+ * illegal one, and hosts prune blank names on save.
401
+ */
402
+ declare function bindPropertyName(input: HTMLInputElement, onCommit: (value: string) => void, opts?: {
403
+ hint?: string;
404
+ }): void;
405
+ /**
406
+ * The first field in `host` holding a name no expression could reach, for a Save
407
+ * gate. Hosts hand this back beside `dupGuard.firstDuplicate()`: two faults, two
408
+ * sets of words, one gate.
409
+ */
410
+ declare function firstIllegalPropertyName(host: ParentNode): HTMLInputElement | null;
411
+
342
412
  interface GameIdEditorOptions {
343
413
  anchor: HTMLElement;
344
414
  /** The pinned address, or "" when it is being derived. */
@@ -719,4 +789,4 @@ interface StepperBarOptions {
719
789
  /** Draw (or hide) the bar in `host`. Idempotent: call it again with new state. */
720
790
  declare function renderStepperBar(host: HTMLElement, opts: StepperBarOptions): void;
721
791
 
722
- export { type AboutOptions, type AnchoredPanel, type AnchoredPanelOptions, type Child, type Comment, type CommentMessage, type CommentsOptions, type ConfirmOptions, type DocLine, type DupGuard, type ElProps, type GameIdEditorOptions, type IconName, type IconSvgName, type Identity, type IdentityOptions, type JobProgressOptions, type JobProgressView, type Notes, type NotesEditorOptions, PALETTE, PALETTE_SIZE, type PaneShell, type PaneShellOptions, type PaneShellState, type PaneSide, type PaneSideConfig, type PinButton, type PinButtonOptions, type SaveController, type SaveControllerOptions, type SaveIndicator, type SaveStatus, type SettingsDialog, type SettingsDialogOptions, type SettingsSection, type SettingsSectionHandle, type ShardVc, type StaleBarOptions, type StepperBarOptions, type StepperItem, type StepperTone, type TipRect, type TooltipOptions, type VcMap, askIdentity, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isValidGameId, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
792
+ export { type AboutOptions, type AnchoredPanel, type AnchoredPanelOptions, type Child, type Comment, type CommentMessage, type CommentsOptions, type ConfirmOptions, type DocLine, type DupGuard, type ElProps, type GameIdEditorOptions, type IconName, type IconSvgName, type Identity, type IdentityOptions, type JobProgressOptions, type JobProgressView, type Notes, type NotesEditorOptions, PALETTE, PALETTE_SIZE, PROPERTY_NAME_HINT, type PaneShell, type PaneShellOptions, type PaneShellState, type PaneSide, type PaneSideConfig, type PinButton, type PinButtonOptions, RESERVED_PROPERTY_NAMES, type SaveController, type SaveControllerOptions, type SaveIndicator, type SaveStatus, type SettingsDialog, type SettingsDialogOptions, type SettingsSection, type SettingsSectionHandle, type ShardVc, type StaleBarOptions, type StepperBarOptions, type StepperItem, type StepperTone, type TipRect, type TooltipOptions, type VcMap, askIdentity, bindPropertyName, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, firstIllegalPropertyName, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isCaseOnlyPropertyName, isValidGameId, isValidPropertyName, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, propertyNameProblem, propertyNameify, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
package/dist/index.js CHANGED
@@ -860,6 +860,73 @@ function isValidGameId(gameId) {
860
860
  return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(gameId);
861
861
  }
862
862
 
863
+ // src/property-names.ts
864
+ var RESERVED_PROPERTY_NAMES = ["true", "false", "and", "or", "not"];
865
+ var PROPERTY_NAME_HINT = "Lower case letters, digits and underscores. Cannot start with a digit. No hyphens or spaces.";
866
+ function propertyNameify(text) {
867
+ const trimmed = text.trim();
868
+ const deliberateLeading = trimmed.startsWith("_");
869
+ let out = trimmed.toLowerCase().replace(/['’]/g, "").replace(/[^a-z0-9_]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
870
+ if (out === "") return "";
871
+ if (deliberateLeading || /^[0-9]/.test(out)) out = `_${out}`;
872
+ if (RESERVED_PROPERTY_NAMES.includes(out)) out = `${out}_`;
873
+ return out;
874
+ }
875
+ function isValidPropertyName(name) {
876
+ return /^[a-z_][a-z0-9_]*$/.test(name) && !RESERVED_PROPERTY_NAMES.includes(name);
877
+ }
878
+ function isCaseOnlyPropertyName(name) {
879
+ return !isValidPropertyName(name) && isValidPropertyName(name.toLowerCase());
880
+ }
881
+
882
+ // src/property-name-field.ts
883
+ function propertyNameProblem(name) {
884
+ if (isValidPropertyName(name)) return void 0;
885
+ const suggestion = propertyNameify(name);
886
+ const tail = suggestion ? ` Try "${suggestion}", or press Tab.` : "";
887
+ if (RESERVED_PROPERTY_NAMES.includes(name.toLowerCase())) {
888
+ return `Cannot be used: "${name.toLowerCase()}" is a keyword in expressions.${tail}`;
889
+ }
890
+ if (name.includes("-")) return `Cannot be used: a hyphen reads as subtraction in an expression.${tail}`;
891
+ if (/^[0-9]/.test(name)) return `Cannot be used: a name cannot start with a digit.${tail}`;
892
+ if (name !== name.toLowerCase()) {
893
+ return `Cannot be used: expressions fold names, so this would look for "${name.toLowerCase()}".${tail}`;
894
+ }
895
+ return `Cannot be used: only lower case letters, digits and underscores.${tail}`;
896
+ }
897
+ function bindPropertyName(input, onCommit, opts = {}) {
898
+ const hint = opts.hint;
899
+ const sync = () => {
900
+ const v = input.value.trim();
901
+ const problem = v === "" ? void 0 : propertyNameProblem(v);
902
+ input.classList.toggle("illegal", !!problem);
903
+ if (problem) input.title = problem;
904
+ else if (input.title.startsWith("Cannot be used")) {
905
+ if (hint) input.title = hint;
906
+ else input.removeAttribute("title");
907
+ }
908
+ };
909
+ input.addEventListener("input", () => {
910
+ onCommit(input.value);
911
+ sync();
912
+ });
913
+ input.addEventListener("keydown", (e) => {
914
+ if (e.key !== "Tab" || e.shiftKey) return;
915
+ const typed = input.value.trim();
916
+ if (typed === "" || isValidPropertyName(typed)) return;
917
+ const coerced = propertyNameify(typed);
918
+ if (!coerced || coerced === input.value) return;
919
+ e.preventDefault();
920
+ input.value = coerced;
921
+ onCommit(coerced);
922
+ sync();
923
+ });
924
+ sync();
925
+ }
926
+ function firstIllegalPropertyName(host) {
927
+ return host.querySelector("input.illegal");
928
+ }
929
+
863
930
  // src/id-editor.ts
864
931
  function openGameIdEditor(opts) {
865
932
  const slugify = opts.slugify ?? gameIdify;
@@ -1520,6 +1587,6 @@ function renderStepperBar(host, opts) {
1520
1587
  );
1521
1588
  }
1522
1589
 
1523
- export { PALETTE, PALETTE_SIZE, askIdentity, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isValidGameId, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
1590
+ export { PALETTE, PALETTE_SIZE, PROPERTY_NAME_HINT, RESERVED_PROPERTY_NAMES, askIdentity, bindPropertyName, closeAnchoredPanel, closeWithExit, colourFor, colourIndex, confirmDialog, createSaveController, dupGuard, el, expandableRow, firstIllegalPropertyName, focusNewRow, foldVc, gameIdify, hideTip, icon, iconBtn, iconSvg, initTooltips, isCaseOnlyPropertyName, isValidGameId, isValidPropertyName, labelled, lockControls, lockNotice, mountJobProgress, mountPaneShell, mountSettingsDialog, moveItem, openAnchoredPanel, openComments, openGameIdEditor, openNotesEditor, paintVcBadges, pinButton, placeAnchored, propertyNameProblem, propertyNameify, renderStepperBar, saveIndicator, showAbout, staleBar, tagChips, tipAt, tipBold, vcBadgeFor };
1524
1591
  //# sourceMappingURL=index.js.map
1525
1592
  //# sourceMappingURL=index.js.map