@operato/data-grist 10.29.38 → 10.29.39

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/coverage/lcov-report/index.html +169 -169
  3. package/coverage/lcov-report/webpack/bootstrap.html +1 -1
  4. package/coverage/lcov-report/webpack/index.html +1 -1
  5. package/coverage/lcov-report/webpack/runtime/define property getters.html +1 -1
  6. package/coverage/lcov-report/webpack/runtime/global.html +1 -1
  7. package/coverage/lcov-report/webpack/runtime/hasOwnProperty shorthand.html +1 -1
  8. package/coverage/lcov-report/webpack/runtime/index.html +1 -1
  9. package/coverage/lcov-report/webpack/runtime/make namespace object.html +1 -1
  10. package/coverage/lcov.info +57759 -56341
  11. package/dist/src/data-consumer.d.ts +7 -1
  12. package/dist/src/data-consumer.js.map +1 -1
  13. package/dist/src/data-grist.d.ts +19 -3
  14. package/dist/src/data-grist.js +163 -39
  15. package/dist/src/data-grist.js.map +1 -1
  16. package/dist/src/data-provider.d.ts +8 -1
  17. package/dist/src/data-provider.js +94 -46
  18. package/dist/src/data-provider.js.map +1 -1
  19. package/dist/src/editors/ox-grist-editor.d.ts +2 -0
  20. package/dist/src/editors/ox-grist-editor.js +17 -4
  21. package/dist/src/editors/ox-grist-editor.js.map +1 -1
  22. package/dist/src/filters/filter-checkbox.js +3 -2
  23. package/dist/src/filters/filter-checkbox.js.map +1 -1
  24. package/dist/src/filters/filter-input-barcode.js +2 -1
  25. package/dist/src/filters/filter-input-barcode.js.map +1 -1
  26. package/dist/src/filters/filter-input.js +2 -1
  27. package/dist/src/filters/filter-input.js.map +1 -1
  28. package/dist/src/filters/filter-ownership.d.ts +9 -0
  29. package/dist/src/filters/filter-ownership.js +30 -0
  30. package/dist/src/filters/filter-ownership.js.map +1 -0
  31. package/dist/src/filters/filter-range-date.js +3 -2
  32. package/dist/src/filters/filter-range-date.js.map +1 -1
  33. package/dist/src/filters/filter-range-number.js +3 -2
  34. package/dist/src/filters/filter-range-number.js.map +1 -1
  35. package/dist/src/filters/filter-select-buttons.js +2 -1
  36. package/dist/src/filters/filter-select-buttons.js.map +1 -1
  37. package/dist/src/filters/filters-form.js +80 -22
  38. package/dist/src/filters/filters-form.js.map +1 -1
  39. package/dist/src/utils/list-param.d.ts +5 -3
  40. package/dist/src/utils/list-param.js +6 -37
  41. package/dist/src/utils/list-param.js.map +1 -1
  42. package/dist/test/address-intents.test.d.ts +1 -0
  43. package/dist/test/address-intents.test.js +202 -0
  44. package/dist/test/address-intents.test.js.map +1 -0
  45. package/dist/test/filter-ownership.test.d.ts +1 -0
  46. package/dist/test/filter-ownership.test.js +28 -0
  47. package/dist/test/filter-ownership.test.js.map +1 -0
  48. package/dist/test/record-view-popup-editor.test.js +13 -0
  49. package/dist/test/record-view-popup-editor.test.js.map +1 -1
  50. package/dist/test/request-generation.test.d.ts +1 -0
  51. package/dist/test/request-generation.test.js +120 -0
  52. package/dist/test/request-generation.test.js.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +11 -7
  55. package/test/address-intents.test.ts +203 -0
  56. package/test/filter-ownership.test.ts +37 -0
  57. package/test/record-view-popup-editor.test.ts +16 -0
  58. package/test/request-generation.test.ts +128 -0
@@ -1,10 +1,16 @@
1
- import { FetchHandler, GristData } from './types.js';
1
+ import { FetchHandler, FilterValue, GristData, SortersConfig } from './types.js';
2
2
  export interface DataConsumer extends EventTarget {
3
3
  data: any;
4
4
  _data: GristData;
5
5
  mode: 'GRID' | 'LIST' | 'CARD' | 'REPORT';
6
6
  checkDirties(): void;
7
7
  fetchHandler?: FetchHandler;
8
+ filters?: FilterValue[];
9
+ sorters?: SortersConfig;
10
+ searchMode?: string;
11
+ searchText?: string;
12
+ /** A malformed address must be shown as an error, never read as an unfiltered list. */
13
+ allowFetch?: boolean;
8
14
  showSpinner(): void;
9
15
  hideSpinner(): void;
10
16
  /** The fetch threw. Without this the grid kept its old rows or showed "nothing", and said nothing. */
@@ -1 +1 @@
1
- {"version":3,"file":"data-consumer.js","sourceRoot":"","sources":["../../src/data-consumer.ts"],"names":[],"mappings":"","sourcesContent":["import { FetchHandler, GristData } from './types.js'\n\nexport interface DataConsumer extends EventTarget {\n data: any\n _data: GristData\n mode: 'GRID' | 'LIST' | 'CARD' | 'REPORT'\n checkDirties(): void\n fetchHandler?: FetchHandler\n showSpinner(): void\n hideSpinner(): void\n /** The fetch threw. Without this the grid kept its old rows or showed \"nothing\", and said nothing. */\n fetchFailed?(error: unknown): void\n /** The fetch answered. Clears a previous failure. */\n fetchSucceeded?(): void\n}\n"]}
1
+ {"version":3,"file":"data-consumer.js","sourceRoot":"","sources":["../../src/data-consumer.ts"],"names":[],"mappings":"","sourcesContent":["import { FetchHandler, FilterValue, GristData, SortersConfig } from './types.js'\n\nexport interface DataConsumer extends EventTarget {\n data: any\n _data: GristData\n mode: 'GRID' | 'LIST' | 'CARD' | 'REPORT'\n checkDirties(): void\n fetchHandler?: FetchHandler\n filters?: FilterValue[]\n sorters?: SortersConfig\n searchMode?: string\n searchText?: string\n /** A malformed address must be shown as an error, never read as an unfiltered list. */\n allowFetch?: boolean\n showSpinner(): void\n hideSpinner(): void\n /** The fetch threw. Without this the grid kept its old rows or showed \"nothing\", and said nothing. */\n fetchFailed?(error: unknown): void\n /** The fetch answered. Clears a previous failure. */\n fetchSucceeded?(): void\n}\n"]}
@@ -133,9 +133,24 @@ export declare class DataGrist extends LitElement implements DataConsumer {
133
133
  private pulltorefreshHandle?;
134
134
  private headroom?;
135
135
  private headResizeObserver?;
136
- private lastLocation;
136
+ private stopAddress?;
137
+ private addressPath?;
138
+ private addressContext;
139
+ private addressRequest?;
140
+ private addressError?;
141
+ private draftBase?;
142
+ get allowFetch(): boolean;
143
+ /** Shell owns persistence; the grid only supplies its model and query identity. */
144
+ private reportDraft;
145
+ get draftSnapshot(): {
146
+ value: GristData;
147
+ base: string | number | null;
148
+ } | undefined;
149
+ get draftRevision(): string;
150
+ restoreUnsavedDraft(value: GristData, base: string | number | null): void;
151
+ private queryIdentity;
137
152
  private pendingFetch?;
138
- private popstateEventHandler;
153
+ private restoreAddress;
139
154
  private fetchParamsChangeEventHandler;
140
155
  firstUpdated(): Promise<void>;
141
156
  connectedCallback(): Promise<void>;
@@ -214,6 +229,7 @@ export declare class DataGrist extends LitElement implements DataConsumer {
214
229
  * @type {GristData} - An object representing the dirty data.
215
230
  */
216
231
  get dirtyData(): GristData;
232
+ flushEdits(): void;
217
233
  /**
218
234
  * Returns an array of GristRecord objects representing the records in the dirty state. These are
219
235
  * the records that have been added, modified, or deleted but have not been committed to the main
@@ -359,7 +375,7 @@ export declare class DataGrist extends LitElement implements DataConsumer {
359
375
  * 것이라 조건이 걸린 자리에서는 거짓이 된다.
360
376
  */
361
377
  private noteWhenEmpty;
362
- reset(): void;
378
+ reset(discard?: boolean): void;
363
379
  private traverseReset;
364
380
  private traverseExpanded;
365
381
  /**
@@ -12,6 +12,7 @@ import Headroom from '@operato/headroom';
12
12
  import { pulltorefresh } from '@operato/pull-to-refresh';
13
13
  import { HeadroomStyles, ScrollbarStyles, SpinnerStyles } from '@operato/styles';
14
14
  import { SnapshotTaker, TimeCapsule } from '@operato/utils';
15
+ import { addressController, writeAddress } from '@operato/utils/address.js';
15
16
  import { buildConfig } from './configure/config-builder.js';
16
17
  import { ZERO_CONFIG, ZERO_DATA, ZERO_PAGES, ZERO_PAGINATION } from './configure/zero-config.js';
17
18
  import { DataProvider } from './data-provider.js';
@@ -85,49 +86,80 @@ let DataGrist = class DataGrist extends LitElement {
85
86
  this._fetched = false;
86
87
  /* The last fetch threw. Cleared by the next fetch that answers. */
87
88
  this._fetchError = null;
88
- this.lastLocation = {};
89
- this.popstateEventHandler = ((e) => {
90
- const { origin, pathname, search } = window.location;
91
- if (this.lastLocation.origin &&
92
- (this.lastLocation.origin !== origin ||
93
- this.lastLocation.pathname !== pathname ||
94
- this.lastLocation.search === search)) {
95
- return;
96
- }
97
- this.lastLocation = {
98
- origin,
99
- pathname,
100
- search
101
- };
102
- var { filters = [], sorters = [] } = convertSearchStringToListParam(search);
89
+ this.addressContext = {};
90
+ this.restoreAddress = (search) => {
91
+ var _a;
103
92
  try {
104
- if (!isEqual(filters, this.filters) || !isEqual(sorters, this.sorters)) {
93
+ const { filters = [], sorters = [], search: term = '' } = convertSearchStringToListParam(search);
94
+ const wasInvalid = !!this.addressError;
95
+ this.addressError = undefined;
96
+ if (!isEqual(filters, this.filters || []) ||
97
+ !isEqual(sorters, this.sorters || []) ||
98
+ (this.searchMode === 'term' && term !== this._searchTerm) ||
99
+ wasInvalid) {
100
+ this.reportDraft('leave');
105
101
  this.dispatchEvent(new CustomEvent('fetch-params-change', {
106
102
  bubbles: true,
107
103
  composed: true,
108
104
  detail: {
109
105
  filters,
110
106
  sorters,
107
+ ...(this.searchMode === 'term' ? { search: term } : {}),
111
108
  from: 'url-parameter'
112
109
  }
113
110
  }));
111
+ return true;
114
112
  }
115
113
  }
116
114
  catch (e) {
117
- console.error(`invalid fetch params on URL query string : ${e}`);
115
+ this.addressError = e;
116
+ (_a = this.dataProvider) === null || _a === void 0 ? void 0 : _a.invalidate();
117
+ this.hideSpinner();
118
+ this.fetchFailed(e);
118
119
  }
119
- }).bind(this);
120
+ return false;
121
+ };
120
122
  this.fetchParamsChangeEventHandler = ((e) => {
121
- const { sorters, filters, from } = e.detail;
122
- sorters && (this.sorters = sorters);
123
- filters && (this.filters = filters);
124
- if (!this.urlParamsSensitive || from === 'url-parameter') {
123
+ var _a;
124
+ const { sorters, filters, search, from } = e.detail;
125
+ if (!this.urlParamsSensitive || from === 'url-parameter' || from === 'config') {
126
+ sorters && (this.sorters = sorters);
127
+ filters && (this.filters = filters);
128
+ if (search !== undefined && this.searchMode === 'term')
129
+ this._searchTerm = search;
130
+ if (from !== 'config')
131
+ this.dispatchEvent(new CustomEvent('query-state-change', {
132
+ bubbles: true,
133
+ composed: true,
134
+ detail: { filters: this.filters, sorters: this.sorters, search: this.searchText }
135
+ }));
125
136
  return;
126
137
  }
127
- const queryString = convertListParamToSearchString({ filters, sorters, base: window.location.search });
128
- this.lastLocation.search = queryString ? `?${queryString}` : '';
129
- const url = `${window.location.pathname}${this.lastLocation.search}`;
130
- history.pushState({}, document.title, url);
138
+ // This listener runs in capture phase, before the provider can issue a read.
139
+ // Only the committed address's restoration event may mutate or fetch a URL-bound query.
140
+ e.stopImmediatePropagation();
141
+ (_a = this.addressRequest) === null || _a === void 0 ? void 0 : _a.abort();
142
+ const request = (this.addressRequest = new AbortController());
143
+ const url = new URL(addressController().entry.url);
144
+ url.search = convertListParamToSearchString({ filters, sorters, search, base: url.search });
145
+ void writeAddress(url, { signal: request.signal })
146
+ .then(accepted => {
147
+ if (accepted || request.signal.aborted || !this.isConnected)
148
+ return;
149
+ this.dispatchEvent(new CustomEvent('fetch-params-change', {
150
+ bubbles: true,
151
+ composed: true,
152
+ detail: {
153
+ filters: this.filters || [],
154
+ sorters: this.sorters || [],
155
+ search: this._searchTerm,
156
+ from: 'config'
157
+ }
158
+ }));
159
+ // The shared search header is also a query control; restore its committed value on refusal.
160
+ this.dispatchEvent(new CustomEvent('query-state-change', { bubbles: true, composed: true }));
161
+ })
162
+ .catch(error => this.fetchFailed(error));
131
163
  }).bind(this);
132
164
  /* 트리 그리드 단일 셀 복사 폴백: document 레벨에서 Ctrl+C를 수신.
133
165
  * 혼합 화면 등에서 행 클릭 후 scan input이 포커스를 빼앗아가므로
@@ -150,6 +182,34 @@ let DataGrist = class DataGrist extends LitElement {
150
182
  grist.body.copy();
151
183
  };
152
184
  }
185
+ get allowFetch() {
186
+ return !this.addressError;
187
+ }
188
+ /** Shell owns persistence; the grid only supplies its model and query identity. */
189
+ reportDraft(action) {
190
+ if (!this.urlParamsSensitive)
191
+ return;
192
+ this.dispatchEvent(new CustomEvent('list-draft', {
193
+ bubbles: true, composed: true,
194
+ detail: { action, query: this.queryIdentity(), pathname: this.addressPath || location.pathname, source: this }
195
+ }));
196
+ }
197
+ get draftSnapshot() {
198
+ var _a;
199
+ return this.dirtyRecords.length
200
+ ? { value: structuredClone(this.dirtyData), base: this.draftBase === undefined ? JSON.stringify(((_a = this.data) === null || _a === void 0 ? void 0 : _a.records) || []) : this.draftBase }
201
+ : undefined;
202
+ }
203
+ get draftRevision() { var _a; return JSON.stringify(((_a = this.data) === null || _a === void 0 ? void 0 : _a.records) || []); }
204
+ restoreUnsavedDraft(value, base) {
205
+ this.draftBase = base;
206
+ this._data = value;
207
+ if (this.grist)
208
+ this.grist.data = value;
209
+ }
210
+ queryIdentity(filters = this.filters || [], sorters = this.sorters || [], search = this.searchMode === 'term' ? this._searchTerm : '') {
211
+ return JSON.stringify({ filters, sorters, search, context: this.addressContext });
212
+ }
153
213
  async firstUpdated() {
154
214
  // Mutation Observer를 사용하여 슬롯의 크기 변경을 감지하고 다시 그린다.
155
215
  const observer = new ResizeObserver(mutationsList => {
@@ -159,25 +219,47 @@ let DataGrist = class DataGrist extends LitElement {
159
219
  }
160
220
  async connectedCallback() {
161
221
  super.connectedCallback();
222
+ // Even an eager initial read must start with the URL's query, before configuration can trigger fetching.
223
+ if (this.urlParamsSensitive) {
224
+ addressController().registerQuery(location.pathname);
225
+ this.addressContext = addressController().params();
226
+ try {
227
+ const query = convertSearchStringToListParam(location.search);
228
+ this.filters = query.filters || [];
229
+ this.sorters = query.sorters || [];
230
+ if (this.searchMode === 'term')
231
+ this._searchTerm = query.search || '';
232
+ }
233
+ catch (error) {
234
+ this.addressError = error;
235
+ this.hideSpinner();
236
+ this.fetchFailed(error);
237
+ }
238
+ }
162
239
  this.dataProvider = new DataProvider(this);
240
+ if (this.urlParamsSensitive)
241
+ this.requestUpdate('urlParamsSensitive', false);
163
242
  this.timeCapsule = new TimeCapsule(10);
164
243
  this.snapshotTaker = new SnapshotTaker(this, this.timeCapsule);
165
- this.addEventListener('fetch-params-change', this.fetchParamsChangeEventHandler);
244
+ this.addEventListener('fetch-params-change', this.fetchParamsChangeEventHandler, true);
166
245
  document.addEventListener('keydown', this._onDocumentKeydown);
167
246
  await this.updateComplete;
168
247
  }
169
248
  disconnectedCallback() {
170
- var _a, _b;
249
+ var _a, _b, _c, _d;
171
250
  super.disconnectedCallback();
172
- this.removeEventListener('fetch-params-change', this.fetchParamsChangeEventHandler);
251
+ this.reportDraft('leave');
252
+ this.removeEventListener('fetch-params-change', this.fetchParamsChangeEventHandler, true);
253
+ (_a = this.stopAddress) === null || _a === void 0 ? void 0 : _a.call(this);
254
+ (_b = this.addressRequest) === null || _b === void 0 ? void 0 : _b.abort();
173
255
  document.removeEventListener('keydown', this._onDocumentKeydown);
174
- (_a = this.headResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
256
+ (_c = this.headResizeObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
175
257
  delete this.headResizeObserver;
176
258
  this.timeCapsule && this.timeCapsule.dispose();
177
259
  this.snapshotTaker && this.snapshotTaker.dispose();
178
260
  delete this.timeCapsule;
179
261
  delete this.snapshotTaker;
180
- (_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.dispose();
262
+ (_d = this.dataProvider) === null || _d === void 0 ? void 0 : _d.dispose();
181
263
  this.resetPullToRefresh();
182
264
  }
183
265
  resetPullToRefresh() {
@@ -514,7 +596,10 @@ let DataGrist = class DataGrist extends LitElement {
514
596
  }
515
597
  }
516
598
  async updated(changes) {
599
+ var _a, _b, _c;
517
600
  var needToSetPullToRefresh = false;
601
+ if (changes.has('_data') && this.dirtyRecords.length)
602
+ this.reportDraft('edit');
518
603
  if (changes.has('filters')) {
519
604
  await this.requestUpdate();
520
605
  }
@@ -535,7 +620,8 @@ let DataGrist = class DataGrist extends LitElement {
535
620
  this.dataProvider && (this.dataProvider.fetchOptions = this.fetchOptions);
536
621
  }
537
622
  if (changes.has('data')) {
538
- this.reset();
623
+ this.reset(false);
624
+ this.reportDraft('loaded');
539
625
  }
540
626
  if (changes.has('mode')) {
541
627
  if (this.mode === 'GRID') {
@@ -563,13 +649,35 @@ let DataGrist = class DataGrist extends LitElement {
563
649
  this.refresh();
564
650
  }
565
651
  if (changes.has('urlParamsSensitive')) {
652
+ (_a = this.stopAddress) === null || _a === void 0 ? void 0 : _a.call(this);
653
+ (_b = this.addressRequest) === null || _b === void 0 ? void 0 : _b.abort();
566
654
  if (this.urlParamsSensitive) {
567
- //@ts-ignore
568
- this.popstateEventHandler(); // call for the first time
569
- window.addEventListener('popstate', this.popstateEventHandler);
655
+ this.addressPath = location.pathname;
656
+ addressController().registerQuery(this.addressPath);
657
+ let activation = true;
658
+ this.stopAddress = addressController().subscribe(entry => {
659
+ var _a, _b, _c;
660
+ if (entry.url.pathname !== this.addressPath) {
661
+ this.reportDraft('leave');
662
+ (_a = this.dataProvider) === null || _a === void 0 ? void 0 : _a.invalidate();
663
+ return;
664
+ }
665
+ const context = addressController().params(entry);
666
+ if (!isEqual(context, this.addressContext)) {
667
+ this.reportDraft('leave');
668
+ (_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.invalidate();
669
+ this.addressContext = context;
670
+ }
671
+ const restored = this.restoreAddress(entry.url.search);
672
+ if (activation && !restored && ((_c = this.dataProvider) === null || _c === void 0 ? void 0 : _c.needsRead))
673
+ void this.fetch();
674
+ activation = false;
675
+ });
570
676
  }
571
677
  else {
572
- window.removeEventListener('popstate', this.popstateEventHandler);
678
+ this.stopAddress = undefined;
679
+ if (changes.get('urlParamsSensitive'))
680
+ (_c = this.dataProvider) === null || _c === void 0 ? void 0 : _c.invalidate();
573
681
  }
574
682
  }
575
683
  if (needToSetPullToRefresh) {
@@ -600,6 +708,18 @@ let DataGrist = class DataGrist extends LitElement {
600
708
  var _a;
601
709
  return ((_a = this.grist) === null || _a === void 0 ? void 0 : _a.data) || {};
602
710
  }
711
+ flushEdits() {
712
+ const visit = (root) => {
713
+ for (const element of Array.from(root.querySelectorAll('*'))) {
714
+ const editor = element;
715
+ if (editor.localName.startsWith('ox-grist-editor') && editor.flush)
716
+ editor.flush();
717
+ else if (editor.shadowRoot)
718
+ visit(editor.shadowRoot);
719
+ }
720
+ };
721
+ visit(this.renderRoot);
722
+ }
603
723
  /**
604
724
  * Returns an array of GristRecord objects representing the records in the dirty state. These are
605
725
  * the records that have been added, modified, or deleted but have not been committed to the main
@@ -907,8 +1027,11 @@ let DataGrist = class DataGrist extends LitElement {
907
1027
  description: given === null || given === void 0 ? void 0 : given.description
908
1028
  };
909
1029
  }
910
- reset() {
1030
+ reset(discard = true) {
911
1031
  var _a, _b;
1032
+ if (discard)
1033
+ this.reportDraft('discard');
1034
+ this.draftBase = undefined;
912
1035
  // TODO tree 형태의 데이타로 _data를 만들 때, children, collapsed 등을 감안한다.
913
1036
  var { limit = ZERO_PAGINATION.limit, page = ZERO_PAGINATION.page, total = ZERO_PAGINATION.total, records = [] } = this.data || ZERO_PAGINATION;
914
1037
  const { childrenProperty, expanded } = this.compiledConfig.tree;
@@ -923,6 +1046,8 @@ let DataGrist = class DataGrist extends LitElement {
923
1046
  total,
924
1047
  records
925
1048
  };
1049
+ if (this.grist)
1050
+ this.grist.data = this._data;
926
1051
  (_a = this.timeCapsule) === null || _a === void 0 ? void 0 : _a.reset();
927
1052
  (_b = this.snapshotTaker) === null || _b === void 0 ? void 0 : _b.take(true);
928
1053
  }
@@ -1124,13 +1249,12 @@ let DataGrist = class DataGrist extends LitElement {
1124
1249
  * 낱말을 그대로 싣는다. 칸의 선언은 보지 않는다 — 두 길이 한 화면에 같이 서면 같은 낱말이
1125
1250
  * 두 번 걸린다.
1126
1251
  */
1127
- this._searchTerm = searchText || '';
1128
1252
  this.grist.dispatchEvent(new CustomEvent('fetch-params-change', {
1129
1253
  bubbles: true,
1130
1254
  composed: true,
1131
1255
  detail: {
1132
1256
  filters,
1133
- search: this._searchTerm
1257
+ search: searchText || ''
1134
1258
  }
1135
1259
  }));
1136
1260
  return;