@lark.js/mvc 0.0.9 → 0.0.10

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
@@ -40,65 +40,30 @@ __export(index_exports, {
40
40
  Updater: () => Updater,
41
41
  VIEW_EVENT_METHOD_REGEXP: () => VIEW_EVENT_METHOD_REGEXP,
42
42
  View: () => View,
43
- applyDomOps: () => applyDomOps,
44
- applyIdUpdates: () => applyIdUpdates,
45
43
  applyStyle: () => applyStyle,
46
- assign: () => assign,
47
44
  bindStore: () => bindStore,
48
45
  computed: () => computed,
49
46
  create: () => create,
50
- createDomRef: () => createDomRef,
51
- defineStore: () => defineStore,
52
47
  defineView: () => defineView,
53
- domGetCompareKey: () => domGetCompareKey,
54
- domGetNode: () => domGetNode,
55
- domSetAttributes: () => domSetAttributes,
56
- domSetChildNodes: () => domSetChildNodes,
57
- domSetNode: () => domSetNode,
58
- domSpecialDiff: () => domSpecialDiff,
59
- domUnmountFrames: () => domUnmountFrames,
60
- encodeHTML: () => encodeHTML,
61
- encodeQ: () => encodeQ,
62
- encodeSafe: () => encodeSafe,
63
- encodeURIExtra: () => encodeURIExtra,
64
- ensureElementId: () => ensureElementId,
65
48
  frameworkConfig: () => config,
66
- funcWithTry: () => funcWithTry,
67
- generateId: () => generateId,
68
- getAttribute: () => getAttribute,
69
- getById: () => getById,
70
49
  getRouteMode: () => getRouteMode,
71
- hasOwnProperty: () => hasOwnProperty,
72
50
  installFrameVisualizerBridge: () => installFrameVisualizerBridge,
73
51
  invalidateViewClass: () => invalidateViewClass,
74
- isPlainObject: () => isPlainObject,
75
- isPrimitive: () => isPrimitive,
76
- isPrimitiveOrFunc: () => isPrimitiveOrFunc,
77
- keys: () => keys,
78
52
  mark: () => mark,
79
53
  markBooted: () => markBooted,
80
54
  markRouterBooted: () => markRouterBooted,
81
55
  nextCounter: () => nextCounter,
82
- nodeInside: () => nodeInside,
83
- noop: () => noop,
84
- now: () => now,
85
- parseUri: () => parseUri,
86
56
  registerViewClass: () => registerViewClass,
87
57
  resetProjectsMap: () => resetProjectsMap,
88
58
  safeguard: () => safeguard,
89
59
  serializeFrameTree: () => serializeFrameTree,
90
- setData: () => setData,
91
- syncCounter: () => syncCounter,
92
- toMap: () => toMap,
93
- toUri: () => toUri,
94
- translateData: () => translateData,
95
60
  unmark: () => unmark,
96
61
  use: () => use,
97
62
  useUrlState: () => useUrlState
98
63
  });
99
64
  module.exports = __toCommonJS(index_exports);
100
65
 
101
- // src/constants.ts
66
+ // src/common.ts
102
67
  var globalCounter = 0;
103
68
  var SPLITTER = String.fromCharCode(30);
104
69
  var RouterEvents = {
@@ -114,6 +79,7 @@ var VIEW_EVENT_METHOD_REGEXP = /^(\$?)([\w]*)<(.*?)>(?:<([\w ,]*)>)?$/;
114
79
  var URL_TRIM_HASH_REGEXP = /(?:^.*\/\/[^/]+|#.*$)/gi;
115
80
  var URL_TRIM_QUERY_REGEXP = /^[^#]*#?!?/;
116
81
  var URL_PARAM_REGEXP = /([^=&?/#]+)=?([^&#?]*)/g;
82
+ var IS_URL_PARAMS = /(?!^)=|&/;
117
83
  var URL_QUERY_HASH_REGEXP = /[#?].*$/;
118
84
  var SVG_NS = "http://www.w3.org/2000/svg";
119
85
  var MATH_NS = "http://www.w3.org/1998/Math/MathML";
@@ -122,13 +88,66 @@ var CALL_BREAK_TIME = 48;
122
88
  function nextCounter() {
123
89
  return ++globalCounter;
124
90
  }
91
+ var HTML_ENT_MAP = {
92
+ "&": "amp",
93
+ "<": "lt",
94
+ ">": "gt",
95
+ '"': "#34",
96
+ "'": "#39",
97
+ "`": "#96"
98
+ };
99
+ var HTML_ENT_REGEXP = /[&<>"'`]/g;
100
+ function encodeSafe(v) {
101
+ return String(v == null ? "" : v);
102
+ }
103
+ function encodeHTML(v) {
104
+ return String(v == null ? "" : v).replace(
105
+ HTML_ENT_REGEXP,
106
+ (m) => "&" + HTML_ENT_MAP[m] + ";"
107
+ );
108
+ }
109
+ var URI_ENT_MAP = {
110
+ "!": "%21",
111
+ "'": "%27",
112
+ "(": "%28",
113
+ ")": "%29",
114
+ "*": "%2A"
115
+ };
116
+ var URI_ENT_REGEXP = /[!')(*]/g;
117
+ function encodeURIExtra(v) {
118
+ return encodeURIComponent(encodeSafe(v)).replace(
119
+ URI_ENT_REGEXP,
120
+ (m) => URI_ENT_MAP[m]
121
+ );
122
+ }
123
+ var QUOTE_ENT_REGEXP = /['"\\]/g;
124
+ function encodeQ(v) {
125
+ return encodeSafe(v).replace(QUOTE_ENT_REGEXP, "\\$&");
126
+ }
127
+ function refFn(ref, value, key) {
128
+ const counter = ref[SPLITTER];
129
+ for (let i = counter; --i; ) {
130
+ key = SPLITTER + i;
131
+ if (ref[key] === value) return key;
132
+ }
133
+ key = SPLITTER + ref[SPLITTER]++;
134
+ ref[key] = value;
135
+ return key;
136
+ }
137
+ function isRefToken(s) {
138
+ if (s.length < 2 || s[0] !== SPLITTER) return false;
139
+ for (let i = 1; i < s.length; i++) {
140
+ const c = s.charCodeAt(i);
141
+ if (c < "0".charCodeAt(0) || c > "9".charCodeAt(0)) return false;
142
+ }
143
+ return true;
144
+ }
125
145
 
126
146
  // src/utils.ts
127
147
  function isPlainObject(value) {
128
148
  if (typeof value !== "object" || value === null) return false;
129
149
  const proto = Object.getPrototypeOf(value);
130
- if (proto === null) return true;
131
- return proto === Object.prototype || proto === null;
150
+ return proto === null || proto === Object.prototype;
132
151
  }
133
152
  function isPrimitiveOrFunc(value) {
134
153
  return !value || typeof value !== "object" && typeof value !== "function";
@@ -140,9 +159,6 @@ var _localCounter = 0;
140
159
  function generateId(prefix) {
141
160
  return (prefix || "lark_") + _localCounter++;
142
161
  }
143
- function syncCounter(val) {
144
- _localCounter = val;
145
- }
146
162
  function noop() {
147
163
  }
148
164
  function hasOwnProperty(owner, prop) {
@@ -197,14 +213,6 @@ function setData(newData, oldData, changedKeys2, excludes) {
197
213
  }
198
214
  return changed;
199
215
  }
200
- function isRefToken(s) {
201
- if (s.length < 2 || s[0] !== SPLITTER) return false;
202
- for (let i = 1; i < s.length; i++) {
203
- const c = s.charCodeAt(i);
204
- if (c < 48 || c > 57) return false;
205
- }
206
- return true;
207
- }
208
216
  function translateData(data, value) {
209
217
  if (isPrimitive(value)) {
210
218
  const prop = String(value);
@@ -233,11 +241,11 @@ function getById(id) {
233
241
  function getAttribute(element, attr) {
234
242
  return Element.prototype.getAttribute.call(element, attr) ?? "";
235
243
  }
236
- function ensureElementId(element) {
244
+ function ensureElementId(element, prefix) {
237
245
  const id = element.getAttribute("id");
238
246
  if (id) return id;
239
247
  element.autoId = 1;
240
- const newId = generateId();
248
+ const newId = generateId(prefix);
241
249
  element.id = newId;
242
250
  return newId;
243
251
  }
@@ -267,11 +275,6 @@ function parseUri(uri) {
267
275
  });
268
276
  return { path: actualPath, params };
269
277
  }
270
- var IS_URL_PARAMS = {
271
- test(s) {
272
- return /(?!^)=|&/.test(s);
273
- }
274
- };
275
278
  function toUri(path, params, keepEmpty) {
276
279
  const pairs = [];
277
280
  let hasParams = false;
@@ -299,7 +302,7 @@ function toMap(list, key) {
299
302
  return map;
300
303
  }
301
304
  function now() {
302
- return Date.now ? Date.now() : (/* @__PURE__ */ new Date()).getTime();
305
+ return Date.now();
303
306
  }
304
307
 
305
308
  // src/apply-style.ts
@@ -938,14 +941,12 @@ function getChanged(oldLoc, newLoc) {
938
941
  setDiff("path", oldLoc["path"], newLoc["path"]);
939
942
  if (changedParams["path"]) {
940
943
  result["path"] = changedParams["path"];
941
- hasChanged = true;
942
944
  result.changed = true;
943
945
  }
944
946
  const viewKey = "view";
945
947
  setDiff(viewKey, oldLoc.view, newLoc.view);
946
948
  if (changedParams[viewKey]) {
947
949
  result.view = changedParams[viewKey];
948
- hasChanged = true;
949
950
  result.changed = true;
950
951
  }
951
952
  const finalResult = {
@@ -1727,57 +1728,8 @@ function applyIdUpdates(updates) {
1727
1728
  }
1728
1729
  }
1729
1730
  }
1730
- var EncoderMap = {
1731
- "&": "amp",
1732
- "<": "lt",
1733
- ">": "gt",
1734
- '"': "#34",
1735
- "'": "#39",
1736
- "`": "#96"
1737
- };
1738
- var ENCODE_REGEXP = /[&<>"'`]/g;
1739
- function encodeHTML(v) {
1740
- return String(v == null ? "" : v).replace(
1741
- ENCODE_REGEXP,
1742
- (m) => "&" + EncoderMap[m] + ";"
1743
- );
1744
- }
1745
- function encodeSafe(v) {
1746
- return String(v == null ? "" : v);
1747
- }
1748
- var URIMap = {
1749
- "!": "%21",
1750
- "'": "%27",
1751
- "(": "%28",
1752
- ")": "%29",
1753
- "*": "%2A"
1754
- };
1755
- var URI_ENCODE_REGEXP = /[!')(*]/g;
1756
- function encodeURIExtra(v) {
1757
- return encodeURIComponent(encodeSafe(v)).replace(
1758
- URI_ENCODE_REGEXP,
1759
- (m) => URIMap[m]
1760
- );
1761
- }
1762
- var QUOTE_REGEXP = /['"\\]/g;
1763
- function encodeQ(v) {
1764
- return encodeSafe(v).replace(QUOTE_REGEXP, "\\$&");
1765
- }
1766
1731
 
1767
1732
  // src/updater.ts
1768
- function updaterRef(refDataIn, value, key) {
1769
- const refData = refDataIn;
1770
- const counter = refData[SPLITTER];
1771
- for (let i = counter; --i; ) {
1772
- key = SPLITTER + i;
1773
- if (refData[key] === value) {
1774
- return key;
1775
- }
1776
- }
1777
- key = SPLITTER + refData[SPLITTER]++;
1778
- refData[key] = value;
1779
- return key;
1780
- }
1781
1733
  var Updater = class {
1782
1734
  /** View ID (same as owner frame ID) */
1783
1735
  viewId;
@@ -1885,7 +1837,7 @@ var Updater = class {
1885
1837
  encodeHTML,
1886
1838
  encodeSafe,
1887
1839
  encodeURIExtra,
1888
- updaterRef,
1840
+ refFn,
1889
1841
  encodeQ
1890
1842
  );
1891
1843
  const newDom = domGetNode(html, node);
@@ -1933,17 +1885,12 @@ var Updater = class {
1933
1885
  * Translate a refData reference back to its original value.
1934
1886
  *
1935
1887
  * The ref protocol is `SPLITTER` + ascii decimal digits — the exact format
1936
- * emitted by `updaterRef`. We require that exact shape so a user-supplied
1888
+ * emitted by `refFn`. We require that exact shape so a user-supplied
1937
1889
  * string that merely begins with SPLITTER is never accidentally resolved
1938
1890
  * (or mishandled as a "missing ref").
1939
1891
  */
1940
1892
  translate(data) {
1941
- if (typeof data !== "string") return data;
1942
- if (data.length < 2 || data[0] !== SPLITTER) return data;
1943
- for (let i = 1; i < data.length; i++) {
1944
- const c = data.charCodeAt(i);
1945
- if (c < 48 || c > 57) return data;
1946
- }
1893
+ if (typeof data !== "string" || !isRefToken(data)) return data;
1947
1894
  return hasOwnProperty(this.refData, data) ? this.refData[data] : data;
1948
1895
  }
1949
1896
  /**
@@ -2010,8 +1957,6 @@ var View = class _View {
2010
1957
  observedStateKeys;
2011
1958
  /** Resource map */
2012
1959
  resources = {};
2013
- /** Assign method reference */
2014
- assignMethod;
2015
1960
  /** Whether endUpdate pending */
2016
1961
  endUpdatePending;
2017
1962
  /** Internal event storage */
@@ -2088,7 +2033,7 @@ var View = class _View {
2088
2033
  */
2089
2034
  beginUpdate(id) {
2090
2035
  if (this.signature > 0 && this.endUpdatePending !== void 0) {
2091
- this.ownerFrame.unmountZone(id, true);
2036
+ this.ownerFrame.unmountZone(id);
2092
2037
  }
2093
2038
  }
2094
2039
  /**
@@ -2107,7 +2052,7 @@ var View = class _View {
2107
2052
  this.rendered = true;
2108
2053
  }
2109
2054
  const ownerFrame = this.ownerFrame;
2110
- ownerFrame.mountZone(updateId, inner);
2055
+ ownerFrame.mountZone(updateId);
2111
2056
  if (!flag) {
2112
2057
  setTimeout(
2113
2058
  this.wrapAsync(() => {
@@ -2332,7 +2277,6 @@ var View = class _View {
2332
2277
  proto["$evtObjMap"] = eventsObject;
2333
2278
  proto["$globalEvtList"] = eventsList;
2334
2279
  proto["$selMap"] = selectorObject;
2335
- proto["$assignFn"] = proto["assign"];
2336
2280
  return makes;
2337
2281
  }
2338
2282
  /**
@@ -2846,7 +2790,7 @@ var Frame = class _Frame extends EventEmitter {
2846
2790
  /**
2847
2791
  * Unmount a child frame.
2848
2792
  */
2849
- unmountFrame(id, _inner) {
2793
+ unmountFrame(id) {
2850
2794
  const targetId = id ? this.childrenMap[id] : this.id;
2851
2795
  const frame = frameRegistry.get(targetId);
2852
2796
  if (!frame) return;
@@ -2868,7 +2812,7 @@ var Frame = class _Frame extends EventEmitter {
2868
2812
  /**
2869
2813
  * Mount all views in a zone.
2870
2814
  */
2871
- mountZone(zoneId, _inner) {
2815
+ mountZone(zoneId) {
2872
2816
  const targetZone = zoneId || this.id;
2873
2817
  this.holdFireCreated = 1;
2874
2818
  const rootEl = document.getElementById(targetZone);
@@ -2878,7 +2822,7 @@ var Frame = class _Frame extends EventEmitter {
2878
2822
  viewElements.forEach((el) => {
2879
2823
  if (!(el instanceof HTMLElement)) return;
2880
2824
  if (htmlElIsBound(el)) return;
2881
- const elId = ensureElementId2(el);
2825
+ const elId = ensureElementId(el, "frame_");
2882
2826
  el.frameBound = 1;
2883
2827
  const viewPath = getAttribute(el, LARK_VIEW);
2884
2828
  frames.push([elId, viewPath]);
@@ -2892,7 +2836,7 @@ var Frame = class _Frame extends EventEmitter {
2892
2836
  /**
2893
2837
  * Unmount all views in a zone.
2894
2838
  */
2895
- unmountZone(zoneId, _inner) {
2839
+ unmountZone(zoneId) {
2896
2840
  for (const childId in this.childrenMap) {
2897
2841
  if (hasOwnProperty(this.childrenMap, childId)) {
2898
2842
  if (!zoneId || childId !== zoneId) {
@@ -3021,17 +2965,6 @@ var Frame = class _Frame extends EventEmitter {
3021
2965
  }
3022
2966
  return rootFrame;
3023
2967
  }
3024
- /**
3025
- * @deprecated Use `Frame.getRoot()` for read-only access or
3026
- * `Frame.createRoot(id)` to create the root explicitly. The single-method
3027
- * `root()` blurred the distinction and was a common source of bugs in
3028
- * Micro-Frontend hosts.
3029
- *
3030
- * Kept for backward compatibility — behavior unchanged.
3031
- */
3032
- static root(rootId) {
3033
- return _Frame.createRoot(rootId);
3034
- }
3035
2968
  /** Bind event listener (static) */
3036
2969
  static on(event, handler) {
3037
2970
  staticEmitter.on(event, handler);
@@ -3050,14 +2983,6 @@ var Frame = class _Frame extends EventEmitter {
3050
2983
  function htmlElIsBound(element) {
3051
2984
  return !!element.frameBound;
3052
2985
  }
3053
- function ensureElementId2(element) {
3054
- const id = element.getAttribute("id");
3055
- if (id) return id;
3056
- element.autoId = 1;
3057
- const newId = generateId("frame_");
3058
- element.id = newId;
3059
- return newId;
3060
- }
3061
2986
  function removeFrame(id, wasCreated) {
3062
2987
  const frameInstance = frameRegistry.get(id);
3063
2988
  if (!frameInstance) return;
@@ -4238,18 +4163,14 @@ function create(name, creator) {
4238
4163
  changedKeys2.add(key);
4239
4164
  }
4240
4165
  }
4241
- let recomputed = false;
4242
4166
  for (const [key, def] of computedDefs) {
4243
4167
  if (def.deps.some((dep) => changedKeys2.has(dep))) {
4244
4168
  const newVal = def.fn();
4245
4169
  if (!Object.is(state[key], newVal)) {
4246
4170
  state[key] = newVal;
4247
- recomputed = true;
4248
4171
  }
4249
4172
  }
4250
4173
  }
4251
- if (recomputed) {
4252
- }
4253
4174
  };
4254
4175
  const subscribe = (listener) => {
4255
4176
  listeners.add(listener);
@@ -4314,7 +4235,6 @@ function bindStore(view, store, selector) {
4314
4235
  view.on("destroy", off);
4315
4236
  return off;
4316
4237
  }
4317
- var defineStore = create;
4318
4238
  // Annotate the CommonJS export names for ESM import in node:
4319
4239
  0 && (module.exports = {
4320
4240
  CALL_BREAK_TIME,
@@ -4337,58 +4257,23 @@ var defineStore = create;
4337
4257
  Updater,
4338
4258
  VIEW_EVENT_METHOD_REGEXP,
4339
4259
  View,
4340
- applyDomOps,
4341
- applyIdUpdates,
4342
4260
  applyStyle,
4343
- assign,
4344
4261
  bindStore,
4345
4262
  computed,
4346
4263
  create,
4347
- createDomRef,
4348
- defineStore,
4349
4264
  defineView,
4350
- domGetCompareKey,
4351
- domGetNode,
4352
- domSetAttributes,
4353
- domSetChildNodes,
4354
- domSetNode,
4355
- domSpecialDiff,
4356
- domUnmountFrames,
4357
- encodeHTML,
4358
- encodeQ,
4359
- encodeSafe,
4360
- encodeURIExtra,
4361
- ensureElementId,
4362
4265
  frameworkConfig,
4363
- funcWithTry,
4364
- generateId,
4365
- getAttribute,
4366
- getById,
4367
4266
  getRouteMode,
4368
- hasOwnProperty,
4369
4267
  installFrameVisualizerBridge,
4370
4268
  invalidateViewClass,
4371
- isPlainObject,
4372
- isPrimitive,
4373
- isPrimitiveOrFunc,
4374
- keys,
4375
4269
  mark,
4376
4270
  markBooted,
4377
4271
  markRouterBooted,
4378
4272
  nextCounter,
4379
- nodeInside,
4380
- noop,
4381
- now,
4382
- parseUri,
4383
4273
  registerViewClass,
4384
4274
  resetProjectsMap,
4385
4275
  safeguard,
4386
4276
  serializeFrameTree,
4387
- setData,
4388
- syncCounter,
4389
- toMap,
4390
- toUri,
4391
- translateData,
4392
4277
  unmark,
4393
4278
  use,
4394
4279
  useUrlState