@wildwinter/app-shell 0.29.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.cjs CHANGED
@@ -891,6 +891,54 @@ function isCaseOnlyPropertyName(name) {
891
891
  return !isValidPropertyName(name) && isValidPropertyName(name.toLowerCase());
892
892
  }
893
893
 
894
+ // src/property-name-field.ts
895
+ function propertyNameProblem(name) {
896
+ if (isValidPropertyName(name)) return void 0;
897
+ const suggestion = propertyNameify(name);
898
+ const tail = suggestion ? ` Try "${suggestion}", or press Tab.` : "";
899
+ if (RESERVED_PROPERTY_NAMES.includes(name.toLowerCase())) {
900
+ return `Cannot be used: "${name.toLowerCase()}" is a keyword in expressions.${tail}`;
901
+ }
902
+ if (name.includes("-")) return `Cannot be used: a hyphen reads as subtraction in an expression.${tail}`;
903
+ if (/^[0-9]/.test(name)) return `Cannot be used: a name cannot start with a digit.${tail}`;
904
+ if (name !== name.toLowerCase()) {
905
+ return `Cannot be used: expressions fold names, so this would look for "${name.toLowerCase()}".${tail}`;
906
+ }
907
+ return `Cannot be used: only lower case letters, digits and underscores.${tail}`;
908
+ }
909
+ function bindPropertyName(input, onCommit, opts = {}) {
910
+ const hint = opts.hint;
911
+ const sync = () => {
912
+ const v = input.value.trim();
913
+ const problem = v === "" ? void 0 : propertyNameProblem(v);
914
+ input.classList.toggle("illegal", !!problem);
915
+ if (problem) input.title = problem;
916
+ else if (input.title.startsWith("Cannot be used")) {
917
+ if (hint) input.title = hint;
918
+ else input.removeAttribute("title");
919
+ }
920
+ };
921
+ input.addEventListener("input", () => {
922
+ onCommit(input.value);
923
+ sync();
924
+ });
925
+ input.addEventListener("keydown", (e) => {
926
+ if (e.key !== "Tab" || e.shiftKey) return;
927
+ const typed = input.value.trim();
928
+ if (typed === "" || isValidPropertyName(typed)) return;
929
+ const coerced = propertyNameify(typed);
930
+ if (!coerced || coerced === input.value) return;
931
+ e.preventDefault();
932
+ input.value = coerced;
933
+ onCommit(coerced);
934
+ sync();
935
+ });
936
+ sync();
937
+ }
938
+ function firstIllegalPropertyName(host) {
939
+ return host.querySelector("input.illegal");
940
+ }
941
+
894
942
  // src/id-editor.ts
895
943
  function openGameIdEditor(opts) {
896
944
  const slugify = opts.slugify ?? gameIdify;
@@ -1562,6 +1610,7 @@ exports.PANE_MENU = PANE_MENU;
1562
1610
  exports.PROPERTY_NAME_HINT = PROPERTY_NAME_HINT;
1563
1611
  exports.RESERVED_PROPERTY_NAMES = RESERVED_PROPERTY_NAMES;
1564
1612
  exports.askIdentity = askIdentity;
1613
+ exports.bindPropertyName = bindPropertyName;
1565
1614
  exports.closeAnchoredPanel = closeAnchoredPanel;
1566
1615
  exports.closeWithExit = closeWithExit;
1567
1616
  exports.colourFor = colourFor;
@@ -1571,6 +1620,7 @@ exports.createSaveController = createSaveController;
1571
1620
  exports.dupGuard = dupGuard;
1572
1621
  exports.el = el;
1573
1622
  exports.expandableRow = expandableRow;
1623
+ exports.firstIllegalPropertyName = firstIllegalPropertyName;
1574
1624
  exports.focusNewRow = focusNewRow;
1575
1625
  exports.foldVc = foldVc;
1576
1626
  exports.gameIdify = gameIdify;
@@ -1596,6 +1646,7 @@ exports.openNotesEditor = openNotesEditor;
1596
1646
  exports.paintVcBadges = paintVcBadges;
1597
1647
  exports.pinButton = pinButton;
1598
1648
  exports.placeAnchored = placeAnchored;
1649
+ exports.propertyNameProblem = propertyNameProblem;
1599
1650
  exports.propertyNameify = propertyNameify;
1600
1651
  exports.renderStepperBar = renderStepperBar;
1601
1652
  exports.saveIndicator = saveIndicator;