@wordpress/views 2.0.0 → 3.1.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/build/index.cjs CHANGED
@@ -1,37 +1,26 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/views/src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- loadView: () => import_load_view.loadView,
24
- useView: () => import_use_view.useView,
25
- useViewConfig: () => import_use_view_config.useViewConfig
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
26
5
  });
27
- module.exports = __toCommonJS(index_exports);
28
- var import_use_view = require("./use-view.cjs");
29
- var import_load_view = require("./load-view.cjs");
30
- var import_use_view_config = require("./use-view-config.cjs");
31
- // Annotate the CommonJS export names for ESM import in node:
32
- 0 && (module.exports = {
33
- loadView,
34
- useView,
35
- useViewConfig
6
+ let __use_view_ts = require("./use-view.cjs");
7
+ let __load_view_ts = require("./load-view.cjs");
8
+ let __use_view_config_ts = require("./use-view-config.cjs");
9
+ Object.defineProperty(exports, "loadView", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return __load_view_ts.loadView;
13
+ }
14
+ });
15
+ Object.defineProperty(exports, "useView", {
16
+ enumerable: true,
17
+ get: function() {
18
+ return __use_view_ts.useView;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "useViewConfig", {
22
+ enumerable: true,
23
+ get: function() {
24
+ return __use_view_config_ts.useViewConfig;
25
+ }
36
26
  });
37
- //# sourceMappingURL=index.cjs.map
@@ -1,57 +1,42 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/views/src/load-view.ts
21
- var load_view_exports = {};
22
- __export(load_view_exports, {
23
- loadView: () => loadView
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(load_view_exports);
26
- var import_data = require("@wordpress/data");
27
- var import_preferences = require("@wordpress/preferences");
28
- var import_preference_keys = require("./preference-keys.cjs");
29
- var import_resolve_view = require("./resolve-view.cjs");
6
+ let _wordpress_data = require("@wordpress/data");
7
+ let _wordpress_preferences = require("@wordpress/preferences");
8
+ let __preference_keys_ts = require("./preference-keys.cjs");
9
+ let __resolve_view_ts = require("./resolve-view.cjs");
10
+ // packages/views/src/load-view.ts
11
+ /**
12
+ * Async function for loading view state in route loaders.
13
+ *
14
+ * Resolves the same layers `useView` does, so a route loader and the hook that
15
+ * takes over from it agree on the view.
16
+ *
17
+ * @param config Configuration object for loading the view.
18
+ * @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').
19
+ * @param config.name Specific entity name.
20
+ * @param config.slug View identifier.
21
+ * @param config.defaultView Default view configuration.
22
+ * @param config.defaultLayouts Default layout configurations keyed by layout type.
23
+ * @param config.activeViewOverrides View overrides applied on top but never persisted.
24
+ * @param config.queryParams Object with `page` and/or `search` from URL.
25
+ * @return Promise resolving to the loaded view object.
26
+ */
30
27
  async function loadView(config) {
31
- const {
32
- kind,
33
- name,
34
- slug,
35
- defaultView,
36
- defaultLayouts,
37
- activeViewOverrides,
38
- queryParams
39
- } = config;
40
- const preferenceKey = (0, import_preference_keys.generatePreferenceKey)(kind, name, slug);
41
- const persistedView = (0, import_data.select)(
42
- import_preferences.store
43
- ).get("core/views", preferenceKey);
44
- return (0, import_resolve_view.resolveView)({
45
- defaultView,
46
- defaultLayouts,
47
- activeViewOverrides,
48
- persistedView,
49
- page: queryParams?.page,
50
- search: queryParams?.search
51
- });
28
+ const { kind, name, slug, defaultView, defaultLayouts, activeViewOverrides, queryParams } = config;
29
+ const preferenceKey = (0, __preference_keys_ts.generatePreferenceKey)(kind, name, slug);
30
+ const persistedView = (0, _wordpress_data.select)(_wordpress_preferences.store).get("core/views", preferenceKey);
31
+ return (0, __resolve_view_ts.resolveView)({
32
+ defaultView,
33
+ defaultLayouts,
34
+ activeViewOverrides,
35
+ persistedView,
36
+ page: queryParams?.page,
37
+ search: queryParams?.search
38
+ });
52
39
  }
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- loadView
56
- });
57
- //# sourceMappingURL=load-view.cjs.map
40
+ exports.loadView = loadView;
41
+
42
+ //# sourceMappingURL=load-view.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/load-view.ts"],
4
- "sourcesContent": ["import { select } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { generatePreferenceKey } from './preference-keys';\nimport { resolveView } from './resolve-view';\nimport type { ViewConfig, ViewOverrides } from './types';\n\n/**\n * Async function for loading view state in route loaders.\n *\n * Resolves the same layers `useView` does, so a route loader and the hook that\n * takes over from it agree on the view.\n *\n * @param config Configuration object for loading the view.\n * @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').\n * @param config.name Specific entity name.\n * @param config.slug View identifier.\n * @param config.defaultView Default view configuration.\n * @param config.defaultLayouts Default layout configurations keyed by layout type.\n * @param config.activeViewOverrides View overrides applied on top but never persisted.\n * @param config.queryParams Object with `page` and/or `search` from URL.\n * @return Promise resolving to the loaded view object.\n */\nexport async function loadView( config: ViewConfig ) {\n\tconst {\n\t\tkind,\n\t\tname,\n\t\tslug,\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tqueryParams,\n\t} = config;\n\tconst preferenceKey = generatePreferenceKey( kind, name, slug );\n\tconst persistedView: ViewOverrides | undefined = select(\n\t\tpreferencesStore\n\t).get( 'core/views', preferenceKey ) as ViewOverrides | undefined;\n\n\treturn resolveView( {\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tpersistedView,\n\t\tpage: queryParams?.page,\n\t\tsearch: queryParams?.search,\n\t} );\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuB;AACvB,yBAA0C;AAC1C,6BAAsC;AACtC,0BAA4B;AAmB5B,eAAsB,SAAU,QAAqB;AACpD,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AACJ,QAAM,oBAAgB,8CAAuB,MAAM,MAAM,IAAK;AAC9D,QAAM,oBAA2C;AAAA,IAChD,mBAAAA;AAAA,EACD,EAAE,IAAK,cAAc,aAAc;AAEnC,aAAO,iCAAa;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,aAAa;AAAA,IACnB,QAAQ,aAAa;AAAA,EACtB,CAAE;AACH;",
6
- "names": ["preferencesStore"]
7
- }
1
+ {"version":3,"file":"load-view.cjs","names":["generatePreferenceKey","select","preferencesStore","resolveView"],"sources":["../src/load-view.ts"],"sourcesContent":["import { select } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { generatePreferenceKey } from './preference-keys';\nimport { resolveView } from './resolve-view';\nimport type { ViewConfig, ViewOverrides } from './types';\n\n/**\n * Async function for loading view state in route loaders.\n *\n * Resolves the same layers `useView` does, so a route loader and the hook that\n * takes over from it agree on the view.\n *\n * @param config Configuration object for loading the view.\n * @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').\n * @param config.name Specific entity name.\n * @param config.slug View identifier.\n * @param config.defaultView Default view configuration.\n * @param config.defaultLayouts Default layout configurations keyed by layout type.\n * @param config.activeViewOverrides View overrides applied on top but never persisted.\n * @param config.queryParams Object with `page` and/or `search` from URL.\n * @return Promise resolving to the loaded view object.\n */\nexport async function loadView( config: ViewConfig ) {\n\tconst {\n\t\tkind,\n\t\tname,\n\t\tslug,\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tqueryParams,\n\t} = config;\n\tconst preferenceKey = generatePreferenceKey( kind, name, slug );\n\tconst persistedView: ViewOverrides | undefined = select(\n\t\tpreferencesStore\n\t).get( 'core/views', preferenceKey ) as ViewOverrides | undefined;\n\n\treturn resolveView( {\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tpersistedView,\n\t\tpage: queryParams?.page,\n\t\tsearch: queryParams?.search,\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,eAAsB,SAAU,QAAqB;CACpD,MAAM,EACL,MACA,MACA,MACA,aACA,gBACA,qBACA,gBACG;CACJ,MAAM,iBAAA,GAAgBA,qBAAAA,sBAAAA,CAAuB,MAAM,MAAM,IAAK;CAC9D,MAAM,iBAAA,GAA2CC,gBAAAA,OAAAA,CAChDC,uBAAAA,KACD,CAAC,CAAC,IAAK,cAAc,aAAc;CAEnC,QAAA,GAAOC,kBAAAA,YAAAA,CAAa;EACnB;EACA;EACA;EACA;EACA,MAAM,aAAa;EACnB,QAAQ,aAAa;CACtB,CAAE;AACH"}
@@ -1,37 +1,11 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/views/src/lock-unlock.ts
21
- var lock_unlock_exports = {};
22
- __export(lock_unlock_exports, {
23
- lock: () => lock,
24
- unlock: () => unlock
25
- });
26
- module.exports = __toCommonJS(lock_unlock_exports);
27
- var import_private_apis = require("@wordpress/private-apis");
28
- var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
29
- "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
30
- "@wordpress/views"
31
- );
32
- // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- lock,
35
- unlock
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
36
5
  });
37
- //# sourceMappingURL=lock-unlock.cjs.map
6
+ // packages/views/src/lock-unlock.ts
7
+ const { lock, unlock } = (0, require("@wordpress/private-apis").__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", "@wordpress/views");
8
+ exports.lock = lock;
9
+ exports.unlock = unlock;
10
+
11
+ //# sourceMappingURL=lock-unlock.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/lock-unlock.ts"],
4
- "sourcesContent": ["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/views'\n\t);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAiE;AAE1D,IAAM,EAAE,MAAM,OAAO,QAC3B;AAAA,EACC;AAAA,EACA;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"lock-unlock.cjs","names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules"],"sources":["../src/lock-unlock.ts"],"sourcesContent":["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/views'\n\t);\n"],"mappings":";;;;;;AAEA,MAAa,EAAE,MAAM,YAAA,G,iCACpBA,CAAAA,CAAAA,iDAAAA,CACC,iIACA,kBACD"}
@@ -1,33 +1,20 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/views/src/preference-keys.ts
21
- var preference_keys_exports = {};
22
- __export(preference_keys_exports, {
23
- generatePreferenceKey: () => generatePreferenceKey
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(preference_keys_exports);
6
+ // packages/views/src/preference-keys.ts
7
+ /**
8
+ * Generates a unique preference key for a DataViews view.
9
+ *
10
+ * @param kind The entity kind (e.g., 'postType', 'root')
11
+ * @param name The specific entity name (e.g., 'post', 'user', 'site')
12
+ * @param slug The specific entity slug (e.g., 'category', 'post', 'all')
13
+ * @return The preference key string
14
+ */
26
15
  function generatePreferenceKey(kind, name, slug) {
27
- return `dataviews-${kind}-${name}-${slug}`;
16
+ return `dataviews-${kind}-${name}-${slug}`;
28
17
  }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- generatePreferenceKey
32
- });
33
- //# sourceMappingURL=preference-keys.cjs.map
18
+ exports.generatePreferenceKey = generatePreferenceKey;
19
+
20
+ //# sourceMappingURL=preference-keys.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/preference-keys.ts"],
4
- "sourcesContent": ["/**\n * Generates a unique preference key for a DataViews view.\n *\n * @param kind The entity kind (e.g., 'postType', 'root')\n * @param name The specific entity name (e.g., 'post', 'user', 'site')\n * @param slug The specific entity slug (e.g., 'category', 'post', 'all')\n * @return The preference key string\n */\nexport function generatePreferenceKey(\n\tkind: string,\n\tname: string,\n\tslug: string\n): string {\n\treturn `dataviews-${ kind }-${ name }-${ slug }`;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,sBACf,MACA,MACA,MACS;AACT,SAAO,aAAc,IAAK,IAAK,IAAK,IAAK,IAAK;AAC/C;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"preference-keys.cjs","names":[],"sources":["../src/preference-keys.ts"],"sourcesContent":["/**\n * Generates a unique preference key for a DataViews view.\n *\n * @param kind The entity kind (e.g., 'postType', 'root')\n * @param name The specific entity name (e.g., 'post', 'user', 'site')\n * @param slug The specific entity slug (e.g., 'category', 'post', 'all')\n * @return The preference key string\n */\nexport function generatePreferenceKey(\n\tkind: string,\n\tname: string,\n\tslug: string\n): string {\n\treturn `dataviews-${ kind }-${ name }-${ slug }`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAQA,SAAgB,sBACf,MACA,MACA,MACS;CACT,OAAO,aAAc,KAAM,GAAI,KAAM,GAAI;AAC1C"}
@@ -1,150 +1,199 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/views/src/resolve-view.ts
21
- var resolve_view_exports = {};
22
- __export(resolve_view_exports, {
23
- getApplicablePersistedView: () => getApplicablePersistedView,
24
- getUserModifications: () => getUserModifications,
25
- resolveView: () => resolveView
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
26
5
  });
27
- module.exports = __toCommonJS(resolve_view_exports);
28
- var import_dequal = require("dequal");
29
- var QUERY_PARAMS = ["page", "search"];
6
+ let dequal = require("dequal");
7
+ // packages/views/src/resolve-view.ts
8
+ /**
9
+ * `page` and `search` are URL-managed: the URL is their only source. They are
10
+ * never persisted, and no other layer may configure them — an absent URL param
11
+ * is indistinguishable from the user having cleared the value, so any fallback
12
+ * would resurrect a cleared search on the next read.
13
+ */
14
+ const QUERY_PARAMS = ["page", "search"];
30
15
  function isPlainObject(value) {
31
- return typeof value === "object" && value !== null && !Array.isArray(value);
16
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
17
  }
18
+ /**
19
+ * Copies a layer without the URL-managed properties.
20
+ *
21
+ * @param layer The layer to copy.
22
+ * @return A copy of the layer with `page` and `search` removed.
23
+ */
33
24
  function withoutQueryParams(layer) {
34
- const result = isPlainObject(layer) ? { ...layer } : {};
35
- for (const key of QUERY_PARAMS) {
36
- delete result[key];
37
- }
38
- return result;
25
+ const result = isPlainObject(layer) ? { ...layer } : {};
26
+ for (const key of QUERY_PARAMS) delete result[key];
27
+ return result;
39
28
  }
29
+ /**
30
+ * Merges a layer on top of another, recursing into plain objects so the upper
31
+ * layer only takes over the leaves it declares. Arrays and scalars are leaves:
32
+ * they are replaced wholesale.
33
+ *
34
+ * Nested properties (`layout.styles.<field>.width`, `groupBy.direction`,
35
+ * `sort.direction`) are merged leaf by leaf: a shallow merge would let a layer
36
+ * that only declares one leaf wipe every sibling the layers below provide.
37
+ *
38
+ * @param lower The layer to merge into.
39
+ * @param upper The layer to merge on top.
40
+ * @return The merged layer.
41
+ */
40
42
  function mergeLayer(lower, upper) {
41
- const result = { ...lower };
42
- for (const key of Object.keys(upper)) {
43
- const value = upper[key];
44
- const current = result[key];
45
- result[key] = isPlainObject(current) && isPlainObject(value) ? mergeLayer(current, value) : value;
46
- }
47
- return result;
43
+ const result = { ...lower };
44
+ for (const key of Object.keys(upper)) {
45
+ const value = upper[key];
46
+ const current = result[key];
47
+ result[key] = isPlainObject(current) && isPlainObject(value) ? mergeLayer(current, value) : value;
48
+ }
49
+ return result;
48
50
  }
51
+ /**
52
+ * The leaves of `value` that differ from `base`. Mirrors `mergeLayer`:
53
+ * `mergeLayer( base, diffLayer( value, base ) )` resolves back to `value`.
54
+ *
55
+ * A persisted leaf that equals both `value` and `base` is kept even though it
56
+ * is not a difference: the preference is shared by every view of the same
57
+ * entity, and such a leaf may only differ from the base of *another* view. In
58
+ * this one, where it coincides with the base, a revert is unobservable — so
59
+ * equality cannot mean the user reverted it. Dropping a persisted leaf
60
+ * requires `value` to actually move away from it, back to `base`.
61
+ *
62
+ * @param value The layer to compare.
63
+ * @param base The layer to compare it against.
64
+ * @param persisted The previously persisted leaves.
65
+ * @return The leaves that differ, as a layer of its own.
66
+ */
49
67
  function diffLayer(value, base, persisted = {}) {
50
- const result = {};
51
- for (const key of Object.keys(value)) {
52
- const next = value[key];
53
- const current = base[key];
54
- const prev = persisted[key];
55
- if (next === void 0) {
56
- continue;
57
- }
58
- if (isPlainObject(next) && isPlainObject(current)) {
59
- const nested = diffLayer(
60
- next,
61
- current,
62
- isPlainObject(prev) ? prev : {}
63
- );
64
- if (Object.keys(nested).length > 0) {
65
- result[key] = nested;
66
- }
67
- } else if (!(0, import_dequal.dequal)(next, current)) {
68
- result[key] = next;
69
- } else if (prev !== void 0 && (0, import_dequal.dequal)(next, prev)) {
70
- result[key] = prev;
71
- }
72
- }
73
- return result;
68
+ const result = {};
69
+ for (const key of Object.keys(value)) {
70
+ const next = value[key];
71
+ const current = base[key];
72
+ const prev = persisted[key];
73
+ if (next === void 0) continue;
74
+ if (isPlainObject(next) && isPlainObject(current)) {
75
+ const nested = diffLayer(next, current, isPlainObject(prev) ? prev : {});
76
+ if (Object.keys(nested).length > 0) result[key] = nested;
77
+ } else if (!(0, dequal.dequal)(next, current)) result[key] = next;
78
+ else if (prev !== void 0 && (0, dequal.dequal)(next, prev)) result[key] = prev;
79
+ }
80
+ return result;
74
81
  }
75
82
  function getLockedFilters(overrides) {
76
- return (overrides?.filters ?? []).filter((filter) => filter.isLocked);
83
+ return (overrides?.filters ?? []).filter((filter) => filter.isLocked);
77
84
  }
85
+ /**
86
+ * Hoists the locked filters an override provides to the front of the view's
87
+ * filters, replacing any same-field filter. Locked filters are not the user's
88
+ * to change, so they are pinned in place instead of taking part in the layer
89
+ * resolution.
90
+ *
91
+ * @param view The view to apply the locked filters to.
92
+ * @param overrides The active view overrides.
93
+ * @return The view with the locked filters applied.
94
+ */
78
95
  function applyLockedFilters(view, overrides) {
79
- const locked = getLockedFilters(overrides);
80
- if (locked.length === 0) {
81
- return view;
82
- }
83
- const rest = (view.filters ?? []).filter(
84
- (filter) => !locked.some((f) => f.field === filter.field)
85
- );
86
- return { ...view, filters: [...locked, ...rest] };
96
+ const locked = getLockedFilters(overrides);
97
+ if (locked.length === 0) return view;
98
+ const rest = (view.filters ?? []).filter((filter) => !locked.some((f) => f.field === filter.field));
99
+ return {
100
+ ...view,
101
+ filters: [...locked, ...rest]
102
+ };
87
103
  }
104
+ /**
105
+ * The user's persisted modifications that still apply.
106
+ *
107
+ * A persisted `type` that `defaultLayouts` does not offer is dropped: DataViews
108
+ * renders nothing for a layout it is not given, and the preference may predate
109
+ * the current set of layouts (a screen that used to offer the list layout, say,
110
+ * and no longer does). The type then resolves out of the layers below, and the
111
+ * other modifications are kept. Without `defaultLayouts` every type is offered.
112
+ *
113
+ * `true` is a valid entry, so the check mirrors DataViews': an entry counts as
114
+ * long as it is truthy.
115
+ *
116
+ * @param persistedView The user's persisted modifications.
117
+ * @param defaultLayouts The layouts on offer, keyed by layout type.
118
+ * @return The modifications that apply, or `undefined` when there are none.
119
+ */
88
120
  function getApplicablePersistedView(persistedView, defaultLayouts) {
89
- if (!persistedView || persistedView.type === void 0 || !defaultLayouts || defaultLayouts[persistedView.type]) {
90
- return persistedView;
91
- }
92
- const { type, ...rest } = persistedView;
93
- return Object.keys(rest).length > 0 ? rest : void 0;
121
+ if (!persistedView || persistedView.type === void 0 || !defaultLayouts || defaultLayouts[persistedView.type]) return persistedView;
122
+ const { type, ...rest } = persistedView;
123
+ return Object.keys(rest).length > 0 ? rest : void 0;
94
124
  }
125
+ /**
126
+ * Resolves the layers below the user's modifications — what a modification has
127
+ * to differ from to count as one. The layout type selects which entry of
128
+ * `defaultLayouts` applies, so the base only makes sense relative to a type.
129
+ *
130
+ * @param layers The layers to resolve.
131
+ * @param effectiveType The layout type to resolve the base at.
132
+ * @return The resolved base view.
133
+ */
95
134
  function resolveBaseView(layers, effectiveType) {
96
- const { defaultView, defaultLayouts, activeViewOverrides } = layers;
97
- const layoutDefaults = defaultLayouts?.[effectiveType];
98
- return applyLockedFilters(
99
- [layoutDefaults, activeViewOverrides].reduce(
100
- (lower, upper) => mergeLayer(lower, withoutQueryParams(upper)),
101
- withoutQueryParams(defaultView)
102
- ),
103
- activeViewOverrides
104
- );
135
+ const { defaultView, defaultLayouts, activeViewOverrides } = layers;
136
+ const layoutDefaults = defaultLayouts?.[effectiveType];
137
+ return applyLockedFilters([layoutDefaults, activeViewOverrides].reduce((lower, upper) => mergeLayer(lower, withoutQueryParams(upper)), withoutQueryParams(defaultView)), activeViewOverrides);
105
138
  }
139
+ /**
140
+ * Resolves a view out of its layers. Later layers override earlier ones:
141
+ *
142
+ * 1. `defaultView`
143
+ * 2. `defaultLayouts` (for the effective type)
144
+ * 3. `activeViewOverrides`
145
+ * 4. the user's persisted modifications (see `getApplicablePersistedView`)
146
+ * 5. the URL query params (`page` and `search` only)
147
+ *
148
+ * @param args See `ResolveViewArgs`.
149
+ * @return The resolved `view`.
150
+ */
106
151
  function resolveView(args) {
107
- const { defaultView, defaultLayouts, activeViewOverrides, page, search } = args;
108
- const persistedView = getApplicablePersistedView(
109
- args.persistedView,
110
- defaultLayouts
111
- );
112
- const effectiveType = persistedView?.type ?? activeViewOverrides?.type ?? defaultView?.type;
113
- const baseView = resolveBaseView(args, effectiveType);
114
- const view = {
115
- ...applyLockedFilters(
116
- mergeLayer(baseView, withoutQueryParams(persistedView)),
117
- activeViewOverrides
118
- ),
119
- page: Number(page ?? 1),
120
- search: search ?? ""
121
- };
122
- return view;
152
+ const { defaultView, defaultLayouts, activeViewOverrides, page, search } = args;
153
+ const persistedView = getApplicablePersistedView(args.persistedView, defaultLayouts);
154
+ return {
155
+ ...applyLockedFilters(mergeLayer(resolveBaseView(args, persistedView?.type ?? activeViewOverrides?.type ?? defaultView?.type), withoutQueryParams(persistedView)), activeViewOverrides),
156
+ page: Number(page ?? 1),
157
+ search: search ?? ""
158
+ };
123
159
  }
160
+ /**
161
+ * The user's modifications: the leaves of the view they interacted with that
162
+ * the layers below do not already resolve to. This is what gets persisted, so
163
+ * that a change to any of those layers keeps showing through the properties the
164
+ * user never touched.
165
+ *
166
+ * Previously persisted leaves that coincide with the base of the current view
167
+ * are carried over rather than dropped: they may still make a difference in
168
+ * another view sharing the preference. See `diffLayer`.
169
+ *
170
+ * The diff basis is resolved at `newView.type`, not at the type the previous
171
+ * resolution used: the type selects the `defaultLayouts` entry, and a layout
172
+ * switch reports the new type together with that entry's values. Diffing them
173
+ * against the previous type's base would persist the difference between the
174
+ * two entries as if the user had picked those values — leaves the layouts
175
+ * already provide, which then linger as phantom modifications after switching
176
+ * back.
177
+ *
178
+ * A persisted `type` the current layouts do not offer never applied (see
179
+ * `getApplicablePersistedView`), so it is not carried over either: the
180
+ * modifications returned replace it with whatever the user picked.
181
+ *
182
+ * @param newView The view the user produced.
183
+ * @param layers The layers the view resolves from. See `ViewLayers`.
184
+ * @return The modified properties, or `undefined` when the user modified none.
185
+ */
124
186
  function getUserModifications(newView, layers) {
125
- const { defaultLayouts, activeViewOverrides } = layers;
126
- const persistedView = getApplicablePersistedView(
127
- layers.persistedView,
128
- defaultLayouts
129
- );
130
- const baseView = resolveBaseView(layers, newView.type);
131
- const modifications = diffLayer(
132
- withoutQueryParams(newView),
133
- withoutQueryParams(baseView),
134
- withoutQueryParams(persistedView)
135
- );
136
- const locked = getLockedFilters(activeViewOverrides);
137
- if (locked.length > 0 && Array.isArray(modifications.filters)) {
138
- modifications.filters = modifications.filters.filter(
139
- (filter) => !locked.some((f) => f.field === filter.field)
140
- );
141
- }
142
- return Object.keys(modifications).length > 0 ? modifications : void 0;
187
+ const { defaultLayouts, activeViewOverrides } = layers;
188
+ const persistedView = getApplicablePersistedView(layers.persistedView, defaultLayouts);
189
+ const baseView = resolveBaseView(layers, newView.type);
190
+ const modifications = diffLayer(withoutQueryParams(newView), withoutQueryParams(baseView), withoutQueryParams(persistedView));
191
+ const locked = getLockedFilters(activeViewOverrides);
192
+ if (locked.length > 0 && Array.isArray(modifications.filters)) modifications.filters = modifications.filters.filter((filter) => !locked.some((f) => f.field === filter.field));
193
+ return Object.keys(modifications).length > 0 ? modifications : void 0;
143
194
  }
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- getApplicablePersistedView,
147
- getUserModifications,
148
- resolveView
149
- });
150
- //# sourceMappingURL=resolve-view.cjs.map
195
+ exports.getApplicablePersistedView = getApplicablePersistedView;
196
+ exports.getUserModifications = getUserModifications;
197
+ exports.resolveView = resolveView;
198
+
199
+ //# sourceMappingURL=resolve-view.cjs.map