@domql/router 3.6.4 → 3.6.7

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/LICENSE CHANGED
@@ -1,21 +1,34 @@
1
- MIT License
1
+ Creative Commons Attribution-NonCommercial 4.0 International License
2
2
 
3
3
  Copyright (c) 2023 symbo.ls
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ This work is licensed under the Creative Commons Attribution-NonCommercial
6
+ 4.0 International License. To view a copy of this license, visit
7
+ https://creativecommons.org/licenses/by-nc/4.0/ or send a letter to
8
+ Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
11
9
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
10
+ You are free to:
14
11
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ Share copy and redistribute the material in any medium or format
13
+ Adapt — remix, transform, and build upon the material
14
+
15
+ Under the following terms:
16
+
17
+ Attribution — You must give appropriate credit, provide a link to the
18
+ license, and indicate if changes were made. You may do so in any
19
+ reasonable manner, but not in any way that suggests the licensor endorses
20
+ you or your use.
21
+
22
+ NonCommercial — You may not use the material for commercial purposes.
23
+
24
+ No additional restrictions — You may not apply legal terms or
25
+ technological measures that legally restrict others from doing anything
26
+ the license permits.
27
+
28
+ THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
29
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
30
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
31
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
32
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
33
+ OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE
34
+ WORK.
package/README.md CHANGED
@@ -115,6 +115,44 @@ router('/unknown', element, {}, {
115
115
 
116
116
  You can also define a `/*` wildcard route as a catch-all fallback.
117
117
 
118
+ ## Custom Router Element
119
+
120
+ Use `customRouterElement` in your `config.js` to route pages into a specific element within the component tree instead of the root. This is useful for persistent layouts where only the content area changes between routes.
121
+
122
+ ```js
123
+ // symbols/config.js
124
+ export default {
125
+ router: {
126
+ customRouterElement: 'Folder.Content'
127
+ }
128
+ }
129
+ ```
130
+
131
+ The value is a dot-separated path resolved from the root element. For example, `'Folder.Content'` means the router will find `root.Folder.Content` and render page content inside it.
132
+
133
+ This allows you to define a layout once in the `/` (main) page and have sub-pages render inside a specific container:
134
+
135
+ ```js
136
+ // pages/main.js — defines the persistent layout
137
+ export const main = {
138
+ extends: 'Layout',
139
+ Folder: {
140
+ Content: {
141
+ // default content for '/' route
142
+ }
143
+ }
144
+ }
145
+
146
+ // pages/team.js — only defines content (rendered inside Folder.Content)
147
+ export const team = {
148
+ state: 'team',
149
+ extends: 'Grid',
150
+ childExtends: 'TeamItem',
151
+ childrenAs: 'state',
152
+ children: (el, s) => s.data,
153
+ }
154
+ ```
155
+
118
156
  ## Options
119
157
 
120
158
  | Option | Type | Default | Description |
package/dist/cjs/index.js CHANGED
@@ -218,8 +218,20 @@ const router = (path, el, state = {}, options = {}) => {
218
218
  if (contentElementKey && opts.removeOldElement) {
219
219
  element[contentElementKey].remove();
220
220
  }
221
+ const originContent = element.__ref?.origin?.content;
222
+ const contentStyles = {};
223
+ if (originContent) {
224
+ for (const k in originContent) {
225
+ const v = originContent[k];
226
+ if (k === "__ref" || k === "props" || k === "node" || k === "parent" || k === "key") continue;
227
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "object" && v !== null && !v.node && !v.__ref) {
228
+ contentStyles[k] = v;
229
+ }
230
+ }
231
+ }
221
232
  element.set(
222
233
  {
234
+ ...contentStyles,
223
235
  tag: opts.useFragment && "fragment",
224
236
  extends: content
225
237
  },
package/dist/esm/index.js CHANGED
@@ -187,8 +187,20 @@ const router = (path, el, state = {}, options = {}) => {
187
187
  if (contentElementKey && opts.removeOldElement) {
188
188
  element[contentElementKey].remove();
189
189
  }
190
+ const originContent = element.__ref?.origin?.content;
191
+ const contentStyles = {};
192
+ if (originContent) {
193
+ for (const k in originContent) {
194
+ const v = originContent[k];
195
+ if (k === "__ref" || k === "props" || k === "node" || k === "parent" || k === "key") continue;
196
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "object" && v !== null && !v.node && !v.__ref) {
197
+ contentStyles[k] = v;
198
+ }
199
+ }
200
+ }
190
201
  element.set(
191
202
  {
203
+ ...contentStyles,
192
204
  tag: opts.useFragment && "fragment",
193
205
  extends: content
194
206
  },
@@ -4,6 +4,9 @@ var DomqlRouter = (() => {
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
7
10
  var __export = (target, all) => {
8
11
  for (var name in all)
9
12
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -18,6 +21,312 @@ var DomqlRouter = (() => {
18
21
  };
19
22
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
23
 
24
+ // ../../packages/utils/dist/esm/globals.js
25
+ var window2, document2;
26
+ var init_globals = __esm({
27
+ "../../packages/utils/dist/esm/globals.js"() {
28
+ window2 = globalThis;
29
+ document2 = window2.document;
30
+ }
31
+ });
32
+
33
+ // ../../packages/utils/dist/esm/node.js
34
+ var init_node = __esm({
35
+ "../../packages/utils/dist/esm/node.js"() {
36
+ }
37
+ });
38
+
39
+ // ../../packages/utils/dist/esm/types.js
40
+ var isFunction;
41
+ var init_types = __esm({
42
+ "../../packages/utils/dist/esm/types.js"() {
43
+ isFunction = (arg) => typeof arg === "function";
44
+ }
45
+ });
46
+
47
+ // ../../packages/utils/dist/esm/array.js
48
+ var init_array = __esm({
49
+ "../../packages/utils/dist/esm/array.js"() {
50
+ }
51
+ });
52
+
53
+ // ../../packages/utils/dist/esm/string.js
54
+ var init_string = __esm({
55
+ "../../packages/utils/dist/esm/string.js"() {
56
+ }
57
+ });
58
+
59
+ // ../../packages/utils/dist/esm/keys.js
60
+ var STATE_METHODS, PROPS_METHODS, METHODS, METHODS_EXL;
61
+ var init_keys = __esm({
62
+ "../../packages/utils/dist/esm/keys.js"() {
63
+ STATE_METHODS = /* @__PURE__ */ new Set([
64
+ "update",
65
+ "parse",
66
+ "clean",
67
+ "create",
68
+ "destroy",
69
+ "add",
70
+ "toggle",
71
+ "remove",
72
+ "apply",
73
+ "set",
74
+ "reset",
75
+ "replace",
76
+ "quietReplace",
77
+ "quietUpdate",
78
+ "applyReplace",
79
+ "applyFunction",
80
+ "keys",
81
+ "values",
82
+ "ref",
83
+ "rootUpdate",
84
+ "parentUpdate",
85
+ "parent",
86
+ "__element",
87
+ "__depends",
88
+ "__ref",
89
+ "__children",
90
+ "root",
91
+ "setByPath",
92
+ "setPathCollection",
93
+ "removeByPath",
94
+ "removePathCollection",
95
+ "getByPath"
96
+ ]);
97
+ PROPS_METHODS = /* @__PURE__ */ new Set(["update", "__element"]);
98
+ METHODS = /* @__PURE__ */ new Set([
99
+ "set",
100
+ "reset",
101
+ "update",
102
+ "remove",
103
+ "updateContent",
104
+ "removeContent",
105
+ "lookup",
106
+ "lookdown",
107
+ "lookdownAll",
108
+ "getRef",
109
+ "getPath",
110
+ "setNodeStyles",
111
+ "spotByPath",
112
+ "keys",
113
+ "parse",
114
+ "setProps",
115
+ "parseDeep",
116
+ "variables",
117
+ "if",
118
+ "log",
119
+ "verbose",
120
+ "warn",
121
+ "error",
122
+ "call",
123
+ "nextElement",
124
+ "previousElement",
125
+ "getRootState",
126
+ "getRoot",
127
+ "getRootData",
128
+ "getRootContext",
129
+ "getContext",
130
+ "getQuery",
131
+ "getDB",
132
+ "getChildren"
133
+ ]);
134
+ METHODS_EXL = /* @__PURE__ */ new Set([
135
+ "node",
136
+ "context",
137
+ "extends",
138
+ "__element",
139
+ "__ref",
140
+ ...METHODS,
141
+ ...STATE_METHODS,
142
+ ...PROPS_METHODS
143
+ ]);
144
+ }
145
+ });
146
+
147
+ // ../../packages/utils/dist/esm/object.js
148
+ var init_object = __esm({
149
+ "../../packages/utils/dist/esm/object.js"() {
150
+ }
151
+ });
152
+
153
+ // ../../packages/utils/dist/esm/key.js
154
+ var init_key = __esm({
155
+ "../../packages/utils/dist/esm/key.js"() {
156
+ }
157
+ });
158
+
159
+ // ../../packages/utils/dist/esm/env.js
160
+ var init_env = __esm({
161
+ "../../packages/utils/dist/esm/env.js"() {
162
+ }
163
+ });
164
+
165
+ // ../../packages/utils/dist/esm/function.js
166
+ var init_function = __esm({
167
+ "../../packages/utils/dist/esm/function.js"() {
168
+ }
169
+ });
170
+
171
+ // ../../packages/utils/dist/esm/if.js
172
+ var init_if = __esm({
173
+ "../../packages/utils/dist/esm/if.js"() {
174
+ }
175
+ });
176
+
177
+ // ../../packages/utils/dist/esm/log.js
178
+ var init_log = __esm({
179
+ "../../packages/utils/dist/esm/log.js"() {
180
+ }
181
+ });
182
+
183
+ // ../../packages/utils/dist/esm/cookie.js
184
+ var isMobile;
185
+ var init_cookie = __esm({
186
+ "../../packages/utils/dist/esm/cookie.js"() {
187
+ isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
188
+ }
189
+ });
190
+
191
+ // ../../packages/utils/dist/esm/tags.js
192
+ var init_tags = __esm({
193
+ "../../packages/utils/dist/esm/tags.js"() {
194
+ }
195
+ });
196
+
197
+ // ../../packages/utils/dist/esm/extends.js
198
+ var init_extends = __esm({
199
+ "../../packages/utils/dist/esm/extends.js"() {
200
+ }
201
+ });
202
+
203
+ // ../../packages/utils/dist/esm/component.js
204
+ var init_component = __esm({
205
+ "../../packages/utils/dist/esm/component.js"() {
206
+ }
207
+ });
208
+
209
+ // ../../packages/utils/dist/esm/props.js
210
+ var init_props = __esm({
211
+ "../../packages/utils/dist/esm/props.js"() {
212
+ }
213
+ });
214
+
215
+ // ../../packages/utils/dist/esm/element.js
216
+ var init_element = __esm({
217
+ "../../packages/utils/dist/esm/element.js"() {
218
+ }
219
+ });
220
+
221
+ // ../../packages/utils/dist/esm/state.js
222
+ var init_state = __esm({
223
+ "../../packages/utils/dist/esm/state.js"() {
224
+ }
225
+ });
226
+
227
+ // ../../packages/utils/dist/esm/scope.js
228
+ var init_scope = __esm({
229
+ "../../packages/utils/dist/esm/scope.js"() {
230
+ }
231
+ });
232
+
233
+ // ../../packages/utils/dist/esm/triggerEvent.js
234
+ var getOnOrPropsEvent, applyEvent, triggerEventOn;
235
+ var init_triggerEvent = __esm({
236
+ "../../packages/utils/dist/esm/triggerEvent.js"() {
237
+ init_types();
238
+ getOnOrPropsEvent = (param, element) => {
239
+ const onEvent = element.on?.[param];
240
+ if (onEvent) return onEvent;
241
+ const props = element.props;
242
+ if (!props) return;
243
+ const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
244
+ return props[propKey];
245
+ };
246
+ applyEvent = (param, element, state, context, options) => {
247
+ if (!isFunction(param)) return;
248
+ try {
249
+ const result = param.call(
250
+ element,
251
+ element,
252
+ state || element.state,
253
+ context || element.context,
254
+ options
255
+ );
256
+ if (result && typeof result.then === "function") {
257
+ result.catch((err) => {
258
+ element.error = err;
259
+ console.error("[DomQL] Async event error:", err);
260
+ });
261
+ }
262
+ return result;
263
+ } catch (err) {
264
+ element.error = err;
265
+ console.error("[DomQL] Event handler error:", err);
266
+ if (element.context?.strictMode) throw err;
267
+ }
268
+ };
269
+ triggerEventOn = (param, element, options) => {
270
+ if (!element) {
271
+ throw new Error("Element is required");
272
+ }
273
+ const appliedFunction = getOnOrPropsEvent(param, element);
274
+ if (appliedFunction) {
275
+ const { state, context } = element;
276
+ return applyEvent(appliedFunction, element, state, context, options);
277
+ }
278
+ };
279
+ }
280
+ });
281
+
282
+ // ../../packages/utils/dist/esm/cache.js
283
+ var init_cache = __esm({
284
+ "../../packages/utils/dist/esm/cache.js"() {
285
+ }
286
+ });
287
+
288
+ // ../../packages/utils/dist/esm/methods.js
289
+ var init_methods = __esm({
290
+ "../../packages/utils/dist/esm/methods.js"() {
291
+ }
292
+ });
293
+
294
+ // ../../packages/utils/dist/esm/update.js
295
+ var init_update = __esm({
296
+ "../../packages/utils/dist/esm/update.js"() {
297
+ }
298
+ });
299
+
300
+ // ../../packages/utils/dist/esm/index.js
301
+ var init_esm = __esm({
302
+ "../../packages/utils/dist/esm/index.js"() {
303
+ init_key();
304
+ init_env();
305
+ init_types();
306
+ init_object();
307
+ init_function();
308
+ init_array();
309
+ init_node();
310
+ init_if();
311
+ init_log();
312
+ init_string();
313
+ init_globals();
314
+ init_cookie();
315
+ init_tags();
316
+ init_component();
317
+ init_props();
318
+ init_extends();
319
+ init_element();
320
+ init_state();
321
+ init_keys();
322
+ init_scope();
323
+ init_methods();
324
+ init_cache();
325
+ init_update();
326
+ init_triggerEvent();
327
+ }
328
+ });
329
+
21
330
  // index.js
22
331
  var index_exports = {};
23
332
  __export(index_exports, {
@@ -31,56 +340,7 @@ var DomqlRouter = (() => {
31
340
  router: () => router,
32
341
  runGuards: () => runGuards
33
342
  });
34
-
35
- // ../../packages/utils/dist/esm/globals.js
36
- var window2 = globalThis;
37
- var document = window2.document;
38
-
39
- // ../../packages/utils/dist/esm/types.js
40
- var isFunction = (arg) => typeof arg === "function";
41
-
42
- // ../../packages/utils/dist/esm/triggerEvent.js
43
- var getOnOrPropsEvent = (param, element) => {
44
- const onEvent = element.on?.[param];
45
- if (onEvent) return onEvent;
46
- const props = element.props;
47
- if (!props) return;
48
- const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
49
- return props[propKey];
50
- };
51
- var applyEvent = (param, element, state, context, options) => {
52
- if (!isFunction(param)) return;
53
- try {
54
- const result = param.call(
55
- element,
56
- element,
57
- state || element.state,
58
- context || element.context,
59
- options
60
- );
61
- if (result && typeof result.then === "function") {
62
- result.catch((err) => {
63
- element.error = err;
64
- console.error("[DomQL] Async event error:", err);
65
- });
66
- }
67
- return result;
68
- } catch (err) {
69
- element.error = err;
70
- console.error("[DomQL] Event handler error:", err);
71
- if (element.context?.strictMode) throw err;
72
- }
73
- };
74
- var triggerEventOn = (param, element, options) => {
75
- if (!element) {
76
- throw new Error("Element is required");
77
- }
78
- const appliedFunction = getOnOrPropsEvent(param, element);
79
- if (appliedFunction) {
80
- const { state, context } = element;
81
- return applyEvent(appliedFunction, element, state, context, options);
82
- }
83
- };
343
+ init_esm();
84
344
 
85
345
  // ../../packages/element/dist/esm/set.js
86
346
  var setContentKey = (element, opts = {}) => {
@@ -206,7 +466,7 @@ var DomqlRouter = (() => {
206
466
  initialRender: false,
207
467
  scrollToTop: true,
208
468
  scrollToNode: false,
209
- scrollNode: document && document.documentElement,
469
+ scrollNode: document2 && document2.documentElement,
210
470
  scrollBody: false,
211
471
  useFragment: false,
212
472
  updateState: true,
@@ -218,7 +478,7 @@ var DomqlRouter = (() => {
218
478
  var router = (path, el, state = {}, options = {}) => {
219
479
  const element = el || void 0;
220
480
  const win = element.context.window || window2;
221
- const doc = element.context.document || document;
481
+ const doc = element.context.document || document2;
222
482
  const opts = {
223
483
  ...defaultOptions,
224
484
  ...element.context.routerOptions,
@@ -280,8 +540,20 @@ var DomqlRouter = (() => {
280
540
  if (contentElementKey && opts.removeOldElement) {
281
541
  element[contentElementKey].remove();
282
542
  }
543
+ const originContent = element.__ref?.origin?.content;
544
+ const contentStyles = {};
545
+ if (originContent) {
546
+ for (const k in originContent) {
547
+ const v = originContent[k];
548
+ if (k === "__ref" || k === "props" || k === "node" || k === "parent" || k === "key") continue;
549
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "object" && v !== null && !v.node && !v.__ref) {
550
+ contentStyles[k] = v;
551
+ }
552
+ }
553
+ }
283
554
  element.set(
284
555
  {
556
+ ...contentStyles,
285
557
  tag: opts.useFragment && "fragment",
286
558
  extends: content
287
559
  },
@@ -318,3 +590,4 @@ var DomqlRouter = (() => {
318
590
  var index_default = router;
319
591
  return __toCommonJS(index_exports);
320
592
  })();
593
+ // @preserve-env
package/index.js CHANGED
@@ -245,8 +245,23 @@ export const router = (path, el, state = {}, options = {}) => {
245
245
  element[contentElementKey].remove()
246
246
  }
247
247
 
248
+ // Merge parent's original content definition (styles like overflow, maxHeight)
249
+ // with the route's content component
250
+ const originContent = element.__ref?.origin?.content
251
+ const contentStyles = {}
252
+ if (originContent) {
253
+ for (const k in originContent) {
254
+ const v = originContent[k]
255
+ if (k === '__ref' || k === 'props' || k === 'node' || k === 'parent' || k === 'key') continue
256
+ if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || (typeof v === 'object' && v !== null && !v.node && !v.__ref)) {
257
+ contentStyles[k] = v
258
+ }
259
+ }
260
+ }
261
+
248
262
  element.set(
249
263
  {
264
+ ...contentStyles,
250
265
  tag: opts.useFragment && 'fragment',
251
266
  extends: content
252
267
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "3.6.4",
4
- "license": "MIT",
3
+ "version": "3.6.7",
4
+ "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
7
7
  "unpkg": "./dist/iife/index.js",
@@ -27,8 +27,8 @@
27
27
  "prepublish": "npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/element": "^3.6.4",
31
- "@domql/utils": "^3.6.4"
30
+ "@domql/element": "^3.6.7",
31
+ "@domql/utils": "^3.6.7"
32
32
  },
33
33
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
34
34
  "devDependencies": {