@byteluck-fe/model-driven-driven 7.0.0-props.98 → 8.0.0-beta.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.
Files changed (37) hide show
  1. package/README.md +9 -0
  2. package/dist/esm/Builder.js +2 -6
  3. package/dist/esm/Designer.js +31 -42
  4. package/dist/esm/Driven.js +20 -29
  5. package/dist/esm/Plugin.js +1 -3
  6. package/dist/esm/Store.js +7 -9
  7. package/dist/esm/headless/build-info.js +58 -0
  8. package/dist/esm/headless/control-node.factory.js +669 -0
  9. package/dist/esm/headless/control-tree.js +106 -0
  10. package/dist/esm/headless/index.js +11 -0
  11. package/dist/esm/headless/locale.js +159 -0
  12. package/dist/esm/headless/model-bindings.js +265 -0
  13. package/dist/esm/headless/page-compiler.js +47 -0
  14. package/dist/esm/headless/page-template.factory.js +134 -0
  15. package/dist/esm/headless/permissions.js +334 -0
  16. package/dist/esm/headless/saved-model.encoder.js +135 -0
  17. package/dist/esm/headless/session.js +71 -0
  18. package/dist/esm/headless/types.js +149 -0
  19. package/dist/esm/headless/validator.js +140 -0
  20. package/dist/esm/utils.js +15 -16
  21. package/dist/headless/index.js +1 -0
  22. package/dist/headless/index.mjs +1 -0
  23. package/dist/index.umd.js +11 -3
  24. package/dist/types/headless/build-info.d.ts +5 -0
  25. package/dist/types/headless/control-node.factory.d.ts +3 -0
  26. package/dist/types/headless/control-tree.d.ts +9 -0
  27. package/dist/types/headless/index.d.ts +11 -0
  28. package/dist/types/headless/locale.d.ts +26 -0
  29. package/dist/types/headless/model-bindings.d.ts +3 -0
  30. package/dist/types/headless/page-compiler.d.ts +5 -0
  31. package/dist/types/headless/page-template.factory.d.ts +2 -0
  32. package/dist/types/headless/permissions.d.ts +5 -0
  33. package/dist/types/headless/saved-model.encoder.d.ts +5 -0
  34. package/dist/types/headless/session.d.ts +11 -0
  35. package/dist/types/headless/types.d.ts +36 -0
  36. package/dist/types/headless/validator.d.ts +9 -0
  37. package/package.json +29 -7
@@ -0,0 +1,134 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else obj[key] = value;
10
+ return obj;
11
+ }
12
+ function _object_spread(target) {
13
+ for(var i = 1; i < arguments.length; i++){
14
+ var source = arguments[i] != null ? arguments[i] : {};
15
+ var ownKeys = Object.keys(source);
16
+ if (typeof Object.getOwnPropertySymbols === "function") {
17
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
18
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
19
+ }));
20
+ }
21
+ ownKeys.forEach(function(key) {
22
+ _define_property(target, key, source[key]);
23
+ });
24
+ }
25
+ return target;
26
+ }
27
+ function ownKeys(object, enumerableOnly) {
28
+ var keys = Object.keys(object);
29
+ if (Object.getOwnPropertySymbols) {
30
+ var symbols = Object.getOwnPropertySymbols(object);
31
+ if (enumerableOnly) {
32
+ symbols = symbols.filter(function(sym) {
33
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
34
+ });
35
+ }
36
+ keys.push.apply(keys, symbols);
37
+ }
38
+ return keys;
39
+ }
40
+ function _object_spread_props(target, source) {
41
+ source = source != null ? source : {};
42
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
43
+ else {
44
+ ownKeys(Object(source)).forEach(function(key) {
45
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
46
+ });
47
+ }
48
+ return target;
49
+ }
50
+ import { createControlNode, createSequentialIdFactory } from './control-node.factory';
51
+ import { getHeadlessMessageFact, resolveHeadlessMessage } from './locale';
52
+ function templateText(key, options) {
53
+ return resolveHeadlessMessage(getHeadlessMessageFact(key), options);
54
+ }
55
+ export function createPageRoot(kind) {
56
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
57
+ var scopedOptions = options.idFactory ? options : _object_spread_props(_object_spread({}, options), {
58
+ idFactory: createSequentialIdFactory()
59
+ });
60
+ if (kind === 'form') {
61
+ return createControlNode({
62
+ type: 'data-view',
63
+ children: [
64
+ createControlNode('title', scopedOptions),
65
+ createControlNode('grid', scopedOptions)
66
+ ]
67
+ }, scopedOptions);
68
+ }
69
+ if (kind !== 'list') {
70
+ throw new TypeError("Unsupported page kind: ".concat(String(kind)));
71
+ }
72
+ var gridTable = createControlNode('grid-table', scopedOptions);
73
+ gridTable.children = [
74
+ createControlNode('list-page-btn-export-list', scopedOptions),
75
+ createControlNode('list-page-btn-export-record', scopedOptions)
76
+ ];
77
+ return createControlNode({
78
+ type: 'list-view',
79
+ props: {
80
+ countType: 'async',
81
+ rowStyle: {
82
+ type: 'rules',
83
+ interval: {
84
+ color: ''
85
+ },
86
+ rules: [
87
+ {
88
+ id: 'default',
89
+ name: templateText('approvedDocuments', options),
90
+ color: 'theme',
91
+ filters: [
92
+ {
93
+ ruleId: 1,
94
+ symbol: 'op_equal',
95
+ leftVariableBo: {
96
+ type: 'varchar',
97
+ value: 'process_status',
98
+ name: templateText('processStatus', options)
99
+ },
100
+ checked: false,
101
+ describe: 'ruleLine',
102
+ type: 'condition',
103
+ rightVariableBo: {
104
+ type: 'custom',
105
+ value: [
106
+ 'COMPLETE'
107
+ ],
108
+ displayBos: []
109
+ },
110
+ isLowPerformance: false,
111
+ isMoreRelation: false
112
+ }
113
+ ],
114
+ settings: [
115
+ {
116
+ color: 'theme',
117
+ field_codes: [
118
+ 'process_status'
119
+ ],
120
+ type: 'fontColor',
121
+ scope: 'col'
122
+ }
123
+ ],
124
+ script: "(SpecialMatch(data,sys,'process_status','varchar','op_equal','COMPLETE'))"
125
+ }
126
+ ]
127
+ }
128
+ },
129
+ children: [
130
+ createControlNode('simple-search', scopedOptions),
131
+ gridTable
132
+ ]
133
+ }, scopedOptions);
134
+ }
@@ -0,0 +1,334 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else obj[key] = value;
21
+ return obj;
22
+ }
23
+ function _iterable_to_array(iter) {
24
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
25
+ return Array.from(iter);
26
+ }
27
+ }
28
+ function _iterable_to_array_limit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
49
+ }
50
+ return _arr;
51
+ }
52
+ function _non_iterable_rest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _non_iterable_spread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _object_spread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _define_property(target, key, source[key]);
69
+ });
70
+ }
71
+ return target;
72
+ }
73
+ function ownKeys(object, enumerableOnly) {
74
+ var keys = Object.keys(object);
75
+ if (Object.getOwnPropertySymbols) {
76
+ var symbols = Object.getOwnPropertySymbols(object);
77
+ if (enumerableOnly) {
78
+ symbols = symbols.filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
80
+ });
81
+ }
82
+ keys.push.apply(keys, symbols);
83
+ }
84
+ return keys;
85
+ }
86
+ function _object_spread_props(target, source) {
87
+ source = source != null ? source : {};
88
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
+ else {
90
+ ownKeys(Object(source)).forEach(function(key) {
91
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
+ });
93
+ }
94
+ return target;
95
+ }
96
+ function _sliced_to_array(arr, i) {
97
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
98
+ }
99
+ function _to_consumable_array(arr) {
100
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
101
+ }
102
+ function _type_of(obj) {
103
+ "@swc/helpers - typeof";
104
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
105
+ }
106
+ function _unsupported_iterable_to_array(o, minLen) {
107
+ if (!o) return;
108
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
109
+ var n = Object.prototype.toString.call(o).slice(8, -1);
110
+ if (n === "Object" && o.constructor) n = o.constructor.name;
111
+ if (n === "Map" || n === "Set") return Array.from(n);
112
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
113
+ }
114
+ import { getControlDefinition } from '@byteluck-fe/model-driven-controls/catalog';
115
+ import { getHeadlessMessageFact, normalizeHeadlessLocale, resolveHeadlessMessage } from './locale';
116
+ var PERMISSION_EXCLUDED_TYPES = new Set([
117
+ 'title',
118
+ 'grid-table-column',
119
+ 'subtable-column',
120
+ 'operation-column',
121
+ 'data-view',
122
+ 'list-view',
123
+ 'header',
124
+ 'footer',
125
+ 'simple-search',
126
+ 'row',
127
+ 'grid-row',
128
+ 'col',
129
+ 'grid',
130
+ 'divider',
131
+ 'tab-pane',
132
+ 'tab',
133
+ 'card-group',
134
+ 'action-bar',
135
+ 'grid-layout-container',
136
+ 'grid-layout-wrap'
137
+ ]);
138
+ var OPERATION_PERMISSIONS = {
139
+ check: {
140
+ controlId: 'listPageCheckBtnId',
141
+ messageFact: 'permissionView'
142
+ },
143
+ edit: {
144
+ controlId: 'listPageEditBtnId',
145
+ messageFact: 'permissionEdit'
146
+ },
147
+ delete: {
148
+ controlId: 'listPageDeleteBtnId',
149
+ messageFact: 'permissionDelete'
150
+ }
151
+ };
152
+ function stringProp(node, key) {
153
+ var value = node.props[key];
154
+ return typeof value === 'string' ? value : '';
155
+ }
156
+ function fieldGroup(node) {
157
+ if (node.controlType !== 'form' && node.controlType !== 'column') {
158
+ return 'element';
159
+ }
160
+ var dataBind = node.props.dataBind;
161
+ if ((typeof dataBind === "undefined" ? "undefined" : _type_of(dataBind)) !== 'object' || dataBind === null || Array.isArray(dataBind)) {
162
+ return 'element';
163
+ }
164
+ return typeof dataBind.fieldCode === 'string' && dataBind.fieldCode !== '' ? 'field' : 'element';
165
+ }
166
+ function headers(node) {
167
+ return Array.isArray(node.props.headers) ? node.props.headers.filter(function(item) {
168
+ return (typeof item === "undefined" ? "undefined" : _type_of(item)) === 'object' && item !== null && typeof item.type === 'string';
169
+ }) : [];
170
+ }
171
+ function visit(node, parent, context) {
172
+ var result = [];
173
+ var current;
174
+ var definition = getControlDefinition(node.type);
175
+ if (!PERMISSION_EXCLUDED_TYPES.has(node.type)) {
176
+ var _ref;
177
+ var fallbackCaption = (definition === null || definition === void 0 ? void 0 : definition.displayNameFallback) || (definition === null || definition === void 0 ? void 0 : definition.name) || node.type;
178
+ var defaultCaption = resolveHeadlessMessage({
179
+ key: (definition === null || definition === void 0 ? void 0 : definition.displayNameMessageKey) || "model-driven.control.".concat(node.type, ".displayName"),
180
+ fallback: fallbackCaption,
181
+ values: (definition === null || definition === void 0 ? void 0 : definition.localizedDisplayNames) || {}
182
+ }, context);
183
+ current = {
184
+ controlId: node.id,
185
+ caption: stringProp(node, 'caption') || stringProp(node, 'content') || stringProp(node, 'title') || defaultCaption,
186
+ type: node.type,
187
+ controlType: node.controlType,
188
+ parentId: (_ref = parent === null || parent === void 0 ? void 0 : parent.controlId) !== null && _ref !== void 0 ? _ref : null,
189
+ canEdit: node.type !== 'calc',
190
+ canRead: true,
191
+ canHide: true,
192
+ group: fieldGroup(node)
193
+ };
194
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'subtable') {
195
+ current.caption = "".concat(parent.caption, "_").concat(current.caption);
196
+ }
197
+ if (node.type === 'vue-form-item') {
198
+ current.caption = stringProp(node, 'controlExportName') || defaultCaption;
199
+ }
200
+ result.push(current);
201
+ if (node.type === 'vue-form-item' && Array.isArray(node.props.permissions)) {
202
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
203
+ try {
204
+ for(var _iterator = node.props.permissions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
205
+ var permission = _step.value;
206
+ if ((typeof permission === "undefined" ? "undefined" : _type_of(permission)) !== 'object' || permission === null || Array.isArray(permission)) {
207
+ continue;
208
+ }
209
+ if (typeof permission.key !== 'string' || typeof permission.caption !== 'string') {
210
+ continue;
211
+ }
212
+ result.push({
213
+ controlId: permission.key,
214
+ caption: permission.caption,
215
+ type: node.type,
216
+ controlType: node.controlType,
217
+ parentId: node.id,
218
+ canEdit: true,
219
+ canRead: true,
220
+ canHide: true,
221
+ group: fieldGroup(node)
222
+ });
223
+ }
224
+ } catch (err) {
225
+ _didIteratorError = true;
226
+ _iteratorError = err;
227
+ } finally{
228
+ try {
229
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
230
+ _iterator.return();
231
+ }
232
+ } finally{
233
+ if (_didIteratorError) {
234
+ throw _iteratorError;
235
+ }
236
+ }
237
+ }
238
+ }
239
+ } else if (node.type === 'operation-column') {
240
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
241
+ try {
242
+ for(var _iterator1 = Object.entries(OPERATION_PERMISSIONS)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
243
+ var _step_value = _sliced_to_array(_step1.value, 2), propertyKey = _step_value[0], permission1 = _step_value[1];
244
+ var _ref1;
245
+ var operation = node.props[propertyKey];
246
+ if ((typeof operation === "undefined" ? "undefined" : _type_of(operation)) !== 'object' || operation === null || Array.isArray(operation) || operation.isShow !== true) {
247
+ continue;
248
+ }
249
+ result.push({
250
+ controlId: permission1.controlId,
251
+ caption: resolveHeadlessMessage(getHeadlessMessageFact(permission1.messageFact), context),
252
+ type: node.type,
253
+ controlType: node.controlType,
254
+ parentId: (_ref1 = parent === null || parent === void 0 ? void 0 : parent.controlId) !== null && _ref1 !== void 0 ? _ref1 : null,
255
+ canEdit: false,
256
+ canRead: false,
257
+ canHide: true,
258
+ group: 'element'
259
+ });
260
+ }
261
+ } catch (err) {
262
+ _didIteratorError1 = true;
263
+ _iteratorError1 = err;
264
+ } finally{
265
+ try {
266
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
267
+ _iterator1.return();
268
+ }
269
+ } finally{
270
+ if (_didIteratorError1) {
271
+ throw _iteratorError1;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
277
+ try {
278
+ // 与旧 LayoutControl 一致:children 不自动挂在容器权限下。
279
+ for(var _iterator2 = (node.children || [])[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
280
+ var child = _step2.value;
281
+ var _result;
282
+ (_result = result).push.apply(_result, _to_consumable_array(visit(child, parent, context)));
283
+ }
284
+ } catch (err) {
285
+ _didIteratorError2 = true;
286
+ _iteratorError2 = err;
287
+ } finally{
288
+ try {
289
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
290
+ _iterator2.return();
291
+ }
292
+ } finally{
293
+ if (_didIteratorError2) {
294
+ throw _iteratorError2;
295
+ }
296
+ }
297
+ }
298
+ if (node.controlType === 'list') {
299
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
300
+ try {
301
+ for(var _iterator3 = headers(node)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
302
+ var header = _step3.value;
303
+ var _result1;
304
+ (_result1 = result).push.apply(_result1, _to_consumable_array(visit(header, current, context)));
305
+ }
306
+ } catch (err) {
307
+ _didIteratorError3 = true;
308
+ _iteratorError3 = err;
309
+ } finally{
310
+ try {
311
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
312
+ _iterator3.return();
313
+ }
314
+ } finally{
315
+ if (_didIteratorError3) {
316
+ throw _iteratorError3;
317
+ }
318
+ }
319
+ }
320
+ }
321
+ return result;
322
+ }
323
+ export function generatePermissions(controls) {
324
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
325
+ var nodes = Array.isArray(controls) ? controls : [
326
+ controls
327
+ ];
328
+ var context = _object_spread_props(_object_spread({}, options), {
329
+ locale: normalizeHeadlessLocale(options.locale)
330
+ });
331
+ return nodes.flatMap(function(node) {
332
+ return visit(node, undefined, context);
333
+ });
334
+ }
@@ -0,0 +1,135 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else obj[key] = value;
18
+ return obj;
19
+ }
20
+ function _iterable_to_array_limit(arr, i) {
21
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
22
+ if (_i == null) return;
23
+ var _arr = [];
24
+ var _n = true;
25
+ var _d = false;
26
+ var _s, _e;
27
+ try {
28
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
29
+ _arr.push(_s.value);
30
+ if (i && _arr.length === i) break;
31
+ }
32
+ } catch (err) {
33
+ _d = true;
34
+ _e = err;
35
+ } finally{
36
+ try {
37
+ if (!_n && _i["return"] != null) _i["return"]();
38
+ } finally{
39
+ if (_d) throw _e;
40
+ }
41
+ }
42
+ return _arr;
43
+ }
44
+ function _non_iterable_rest() {
45
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
+ }
47
+ function _object_spread(target) {
48
+ for(var i = 1; i < arguments.length; i++){
49
+ var source = arguments[i] != null ? arguments[i] : {};
50
+ var ownKeys = Object.keys(source);
51
+ if (typeof Object.getOwnPropertySymbols === "function") {
52
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
53
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
54
+ }));
55
+ }
56
+ ownKeys.forEach(function(key) {
57
+ _define_property(target, key, source[key]);
58
+ });
59
+ }
60
+ return target;
61
+ }
62
+ function _sliced_to_array(arr, i) {
63
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
64
+ }
65
+ function _type_of(obj) {
66
+ "@swc/helpers - typeof";
67
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
68
+ }
69
+ function _unsupported_iterable_to_array(o, minLen) {
70
+ if (!o) return;
71
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
72
+ var n = Object.prototype.toString.call(o).slice(8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return Array.from(n);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
76
+ }
77
+ function isRecord(value) {
78
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
79
+ }
80
+ function isControlNode(value) {
81
+ return Boolean(isRecord(value) && typeof value.id === 'string' && typeof value.type === 'string' && typeof value.controlType === 'string' && isRecord(value.props));
82
+ }
83
+ function encodeValue(value) {
84
+ if (Array.isArray(value)) return value.map(function(item) {
85
+ return encodeValue(item);
86
+ });
87
+ if (isControlNode(value)) return encodeControlNode(value);
88
+ if (!isRecord(value)) return value;
89
+ return Object.fromEntries(Object.entries(value).map(function(param) {
90
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
91
+ return [
92
+ key,
93
+ encodeValue(item)
94
+ ];
95
+ }));
96
+ }
97
+ export function encodeControlNode(node) {
98
+ return _object_spread({
99
+ id: node.id,
100
+ type: node.type,
101
+ props: encodeValue(node.props),
102
+ // 与旧 toSchema 保持一致:即使值为 undefined,也保留 fieldType 自有 key。
103
+ fieldType: node.fieldType,
104
+ controlType: node.controlType
105
+ }, Array.isArray(node.children) ? {
106
+ children: node.children.map(function(child) {
107
+ return encodeControlNode(child);
108
+ })
109
+ } : {});
110
+ }
111
+ export function encodeSavedModel(nodes) {
112
+ return Array.isArray(nodes) ? nodes.map(function(node) {
113
+ return encodeControlNode(node);
114
+ }) : encodeControlNode(nodes);
115
+ }
116
+ function decamelizeKey(key) {
117
+ return key.replace(/[A-Z]/g, function(letter) {
118
+ return "_".concat(letter.toLowerCase());
119
+ });
120
+ }
121
+ /** 纯递归 key 转换;不依赖 shared 中会读取浏览器状态的根入口。 */ export function decamelizeKeys(value) {
122
+ if (Array.isArray(value)) {
123
+ return value.map(function(item) {
124
+ return decamelizeKeys(item);
125
+ });
126
+ }
127
+ if (!isRecord(value)) return value;
128
+ return Object.fromEntries(Object.entries(value).map(function(param) {
129
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
130
+ return [
131
+ decamelizeKey(key),
132
+ decamelizeKeys(item)
133
+ ];
134
+ }));
135
+ }
@@ -0,0 +1,71 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else obj[key] = value;
10
+ return obj;
11
+ }
12
+ function _object_spread(target) {
13
+ for(var i = 1; i < arguments.length; i++){
14
+ var source = arguments[i] != null ? arguments[i] : {};
15
+ var ownKeys = Object.keys(source);
16
+ if (typeof Object.getOwnPropertySymbols === "function") {
17
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
18
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
19
+ }));
20
+ }
21
+ ownKeys.forEach(function(key) {
22
+ _define_property(target, key, source[key]);
23
+ });
24
+ }
25
+ return target;
26
+ }
27
+ function ownKeys(object, enumerableOnly) {
28
+ var keys = Object.keys(object);
29
+ if (Object.getOwnPropertySymbols) {
30
+ var symbols = Object.getOwnPropertySymbols(object);
31
+ if (enumerableOnly) {
32
+ symbols = symbols.filter(function(sym) {
33
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
34
+ });
35
+ }
36
+ keys.push.apply(keys, symbols);
37
+ }
38
+ return keys;
39
+ }
40
+ function _object_spread_props(target, source) {
41
+ source = source != null ? source : {};
42
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
43
+ else {
44
+ ownKeys(Object(source)).forEach(function(key) {
45
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
46
+ });
47
+ }
48
+ return target;
49
+ }
50
+ import { createControlNode, createSequentialIdFactory } from './control-node.factory';
51
+ import { createPageRoot } from './page-template.factory';
52
+ import { generatePermissions } from './permissions';
53
+ /**
54
+ * 一次页面构建共享一个 idFactory;不同 session 相互隔离,既避免重复 id,也不引入进程全局状态。
55
+ */ export function createHeadlessSession() {
56
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
57
+ var scopedOptions = _object_spread_props(_object_spread({}, options), {
58
+ idFactory: options.idFactory || createSequentialIdFactory()
59
+ });
60
+ return Object.freeze({
61
+ createControlNode: function createControlNode1(input) {
62
+ return createControlNode(input, scopedOptions);
63
+ },
64
+ createPageRoot: function createPageRoot1(kind) {
65
+ return createPageRoot(kind, scopedOptions);
66
+ },
67
+ generatePermissions: function generatePermissions1(controls) {
68
+ return generatePermissions(controls, scopedOptions);
69
+ }
70
+ });
71
+ }