@razaman2/reactive-view 0.0.34 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +459 -125
- package/dist/index.mjs +458 -127
- package/package.json +48 -46
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
|
|
|
19
21
|
}
|
|
20
22
|
return a;
|
|
21
23
|
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
25
|
var __objRest = (source, exclude) => {
|
|
23
26
|
var target = {};
|
|
24
27
|
for (var prop in source)
|
|
@@ -59,16 +62,22 @@ __export(index_exports, {
|
|
|
59
62
|
MergeStyles: () => MergeStyles,
|
|
60
63
|
StyleParser: () => StyleParser,
|
|
61
64
|
access: () => access,
|
|
65
|
+
dataPath: () => dataPath,
|
|
62
66
|
default: () => index_default,
|
|
67
|
+
defineReactiveView: () => defineReactiveView,
|
|
63
68
|
extendVnode: () => extendVnode,
|
|
69
|
+
getData: () => getData,
|
|
64
70
|
getDate: () => getDate,
|
|
65
71
|
getProps: () => getProps,
|
|
66
72
|
getReactiveViewComponent: () => getReactiveViewComponent,
|
|
67
73
|
safeRequest: () => safeRequest,
|
|
74
|
+
setData: () => setData,
|
|
68
75
|
setup: () => setup,
|
|
76
|
+
showComponent: () => showComponent,
|
|
69
77
|
useSubscription: () => useSubscription
|
|
70
78
|
});
|
|
71
79
|
module.exports = __toCommonJS(index_exports);
|
|
80
|
+
var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
|
|
72
81
|
|
|
73
82
|
// src/Subscription.ts
|
|
74
83
|
var Subscription = class _Subscription {
|
|
@@ -168,7 +177,7 @@ var import_vue = require("vue");
|
|
|
168
177
|
|
|
169
178
|
// package.json
|
|
170
179
|
var name = "@razaman2/reactive-view";
|
|
171
|
-
var version = "0.0.
|
|
180
|
+
var version = "0.1.0-beta.2";
|
|
172
181
|
|
|
173
182
|
// src/ReactiveView.ts
|
|
174
183
|
var setup = {
|
|
@@ -179,17 +188,16 @@ var setup = {
|
|
|
179
188
|
var ReactiveView_default = {
|
|
180
189
|
props: {
|
|
181
190
|
setup: {},
|
|
191
|
+
beta: [Boolean, String],
|
|
182
192
|
ReactiveView: {
|
|
183
193
|
type: Boolean,
|
|
184
194
|
default: true
|
|
185
195
|
},
|
|
186
|
-
instance: {
|
|
187
|
-
default: (0, import_vue.ref)()
|
|
188
|
-
},
|
|
196
|
+
instance: { default: (0, import_vue.ref)() },
|
|
189
197
|
notifications: Object,
|
|
190
198
|
subscriptions: Object,
|
|
191
199
|
beforeSetData: Function,
|
|
192
|
-
data: {},
|
|
200
|
+
data: { default: (0, import_vue.reactive)({}) },
|
|
193
201
|
defaultData: {},
|
|
194
202
|
getDefaultData: {
|
|
195
203
|
type: Function,
|
|
@@ -209,142 +217,380 @@ var ReactiveView_default = {
|
|
|
209
217
|
debug: {
|
|
210
218
|
type: Boolean,
|
|
211
219
|
default: false
|
|
212
|
-
}
|
|
220
|
+
},
|
|
221
|
+
state: { default: (0, import_vue.reactive)({}) }
|
|
213
222
|
},
|
|
214
223
|
setup(props, context) {
|
|
215
|
-
var _a, _b, _c
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
var _a, _b, _c;
|
|
225
|
+
const diff = (before, after) => {
|
|
226
|
+
const changed = (0, import_vue.ref)(false);
|
|
227
|
+
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
228
|
+
const changes = paths.reduce((changes2, path) => {
|
|
229
|
+
if (before.get(path) !== after.get(path)) {
|
|
230
|
+
changes2.set(path, after.get(path));
|
|
231
|
+
changed.value = true;
|
|
232
|
+
}
|
|
233
|
+
return changes2;
|
|
234
|
+
}, import_object_manager.default.on({}));
|
|
235
|
+
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
236
|
+
};
|
|
237
|
+
const dataPath2 = (path) => {
|
|
238
|
+
try {
|
|
239
|
+
return context.attrs["data:path"](path);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
return path;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const template = (component, vue2) => {
|
|
245
|
+
return (0, import_vue.createVNode)("div", context.slots.default ? context.attrs : __spreadValues({
|
|
246
|
+
style: { color: "red", textAlign: "center" }
|
|
247
|
+
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
|
|
224
248
|
};
|
|
225
249
|
const isValid = (0, import_vue.ref)(false);
|
|
226
250
|
const isReady = (0, import_vue.ref)(false);
|
|
227
|
-
const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
|
|
228
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
|
|
229
|
-
const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
|
|
230
251
|
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
252
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
253
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
254
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
231
255
|
const vue = (0, import_vue.getCurrentInstance)();
|
|
232
|
-
if (props.debug) {
|
|
233
|
-
console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
234
|
-
}
|
|
235
|
-
if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
|
|
236
|
-
console.error("[ReactiveView]: defaultData is required for function or async data.");
|
|
237
|
-
}
|
|
238
256
|
const defaultData = props.getDefaultData(
|
|
239
|
-
|
|
257
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.unref)(vue.vnode.props.data)) ? [] : {} : {}
|
|
240
258
|
);
|
|
241
259
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
const beta = () => {
|
|
261
|
+
var _a2;
|
|
262
|
+
const emit = (after, before) => {
|
|
263
|
+
if (vue && vue.vnode.el) {
|
|
264
|
+
const event = new CustomEvent("data:emit", {
|
|
265
|
+
bubbles: true,
|
|
266
|
+
// Key: allows it to travel up
|
|
267
|
+
composed: true,
|
|
268
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
269
|
+
detail: { before, after }
|
|
270
|
+
// Payload goes here
|
|
271
|
+
});
|
|
272
|
+
access(component).model.setData(after);
|
|
273
|
+
vue.vnode.el.dispatchEvent(event);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
const proxy = (data) => {
|
|
277
|
+
return new Proxy(data, {
|
|
278
|
+
get(target, key, receiver) {
|
|
279
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
280
|
+
return (...params) => {
|
|
281
|
+
var _a3;
|
|
282
|
+
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
283
|
+
if (typeof beforeSetData === "function") {
|
|
284
|
+
const before = import_object_manager.default.on(target.getData());
|
|
285
|
+
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
286
|
+
const diff2 = access(component).diff(before, after);
|
|
287
|
+
if (beforeSetData(diff2, target)) {
|
|
288
|
+
target[key](...params);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
target[key](...params);
|
|
292
|
+
}
|
|
293
|
+
return target;
|
|
294
|
+
};
|
|
262
295
|
} else {
|
|
263
|
-
target
|
|
296
|
+
return Reflect.get(target, key, receiver);
|
|
264
297
|
}
|
|
265
|
-
|
|
266
|
-
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
const normalize = (data) => {
|
|
302
|
+
const datatype2 = Array.isArray(defaultData) ? [] : {};
|
|
303
|
+
if ((0, import_vue.isRef)(data) || (0, import_vue.isReactive)(data) || isFunctionData || isPromiseData) {
|
|
304
|
+
return (0, import_vue.reactive)(datatype2);
|
|
267
305
|
} else {
|
|
268
|
-
|
|
306
|
+
const props2 = "data" in vue.vnode.props;
|
|
307
|
+
try {
|
|
308
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
309
|
+
return (0, import_vue.reactive)(datatype2);
|
|
310
|
+
} else {
|
|
311
|
+
return (0, import_vue.reactive)(props2 ? { "": datatype2 } : datatype2);
|
|
312
|
+
}
|
|
313
|
+
} catch (e) {
|
|
314
|
+
return (0, import_vue.reactive)(props2 ? { "": datatype2 } : datatype2);
|
|
315
|
+
}
|
|
269
316
|
}
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
const watchDataProp = (dataProp) => {
|
|
273
|
-
var _a2, _b2, _c2;
|
|
274
|
-
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
275
|
-
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
276
|
-
options: Object.assign({
|
|
277
|
-
immediate: context.attrs["data:immediate"],
|
|
278
|
-
deep: context.attrs["data:deep"],
|
|
279
|
-
once: context.attrs["data:once"]
|
|
280
|
-
}, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
|
|
281
317
|
};
|
|
282
|
-
|
|
283
|
-
|
|
318
|
+
const config = {
|
|
319
|
+
data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
|
|
320
|
+
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
321
|
+
notifications: props.notifications,
|
|
322
|
+
subscriptions: props.subscriptions,
|
|
323
|
+
name: props.modelName,
|
|
324
|
+
logging: props.logging
|
|
325
|
+
};
|
|
326
|
+
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config);
|
|
327
|
+
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
328
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
329
|
+
const config2 = {
|
|
330
|
+
callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
|
|
331
|
+
options: {
|
|
332
|
+
immediate: context.attrs["model:immediate"],
|
|
333
|
+
deep: context.attrs["model:deep"],
|
|
334
|
+
once: context.attrs["model:once"]
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const source = () => import_object_manager.default.on(model.getData()).clone();
|
|
338
|
+
(0, import_vue.watch)(source, (after, before) => {
|
|
339
|
+
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
340
|
+
if (props.debug) {
|
|
341
|
+
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
342
|
+
}
|
|
343
|
+
if (diff2.changed) {
|
|
344
|
+
config2.callback(diff2, { component });
|
|
345
|
+
}
|
|
346
|
+
}, config2.options);
|
|
284
347
|
}
|
|
285
|
-
(
|
|
348
|
+
setTimeout(async () => {
|
|
349
|
+
var _a3, _b2, _c2;
|
|
350
|
+
if (props.model !== false) {
|
|
351
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
352
|
+
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
353
|
+
}
|
|
354
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
355
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
356
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
357
|
+
]) : [props.data];
|
|
358
|
+
const isRefData = (0, import_vue.isRef)(data);
|
|
359
|
+
const isReactiveData = (0, import_vue.isReactive)(data);
|
|
360
|
+
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
361
|
+
(0, import_vue.watch)(source, async (after, before) => {
|
|
362
|
+
var _a4;
|
|
363
|
+
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
364
|
+
const callback = context.attrs["data:callback"];
|
|
365
|
+
if (props.debug) {
|
|
366
|
+
console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, isRefData, isReactiveData });
|
|
367
|
+
}
|
|
368
|
+
if (typeof callback === "function") {
|
|
369
|
+
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
370
|
+
} else {
|
|
371
|
+
model.replaceData(after);
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
375
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
376
|
+
once: context.attrs["data:once"]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
setTimeout(async () => {
|
|
381
|
+
var _a3;
|
|
382
|
+
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
383
|
+
});
|
|
384
|
+
component.value = [access(component)].reduce((options, parent) => {
|
|
286
385
|
var _a3;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
386
|
+
while (parent) {
|
|
387
|
+
if (typeof parent.setup === "function") {
|
|
388
|
+
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
389
|
+
if (access(parent.$parent).ReactiveView) {
|
|
390
|
+
break;
|
|
391
|
+
} else {
|
|
392
|
+
parent = access(parent.$parent);
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return options;
|
|
399
|
+
}, component.value);
|
|
400
|
+
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
401
|
+
return (vue2) => {
|
|
402
|
+
var _a3, _b2;
|
|
403
|
+
if (isReady.value) {
|
|
404
|
+
return access(component).template(component, vue2);
|
|
290
405
|
} else {
|
|
291
|
-
|
|
406
|
+
return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
|
|
292
407
|
}
|
|
293
|
-
}
|
|
408
|
+
};
|
|
294
409
|
};
|
|
295
|
-
|
|
296
|
-
var _a2;
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
410
|
+
const current = () => {
|
|
411
|
+
var _a2, _b2, _c2, _d;
|
|
412
|
+
const emit = (after, before) => {
|
|
413
|
+
if (vue && vue.vnode.el) {
|
|
414
|
+
const event = new CustomEvent("data:emit", {
|
|
415
|
+
bubbles: true,
|
|
416
|
+
// Key: allows it to travel up
|
|
417
|
+
composed: true,
|
|
418
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
419
|
+
detail: { before, after }
|
|
420
|
+
// Payload goes here
|
|
421
|
+
});
|
|
422
|
+
vue.vnode.el.dispatchEvent(event);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const normalize = (data) => {
|
|
426
|
+
if (props.debug) {
|
|
427
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: (0, import_vue.isRef)(data), isReactive: (0, import_vue.isReactive)(data) });
|
|
428
|
+
}
|
|
429
|
+
if ((0, import_vue.isReactive)(data)) {
|
|
430
|
+
return data;
|
|
431
|
+
} else {
|
|
432
|
+
if ((0, import_vue.isRef)(data) || isFunctionData || isPromiseData) {
|
|
433
|
+
return (0, import_vue.reactive)(datatype);
|
|
434
|
+
} else {
|
|
435
|
+
const props2 = "data" in vue.vnode.props;
|
|
436
|
+
try {
|
|
437
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
438
|
+
return (0, import_vue.reactive)(props2 ? data : datatype);
|
|
439
|
+
} else {
|
|
440
|
+
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
441
|
+
}
|
|
442
|
+
} catch (e) {
|
|
443
|
+
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const config = {
|
|
449
|
+
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
450
|
+
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
451
|
+
).clone()),
|
|
452
|
+
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
453
|
+
notifications: props.notifications,
|
|
454
|
+
subscriptions: props.subscriptions,
|
|
455
|
+
name: props.modelName,
|
|
456
|
+
logging: props.logging
|
|
457
|
+
};
|
|
458
|
+
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
|
|
459
|
+
get(target, key, receiver) {
|
|
460
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
461
|
+
return (...params) => {
|
|
462
|
+
var _a3;
|
|
463
|
+
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
464
|
+
if (typeof beforeSetData === "function") {
|
|
465
|
+
const before = import_object_manager.default.on(target.getData());
|
|
466
|
+
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
467
|
+
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
468
|
+
target[key](...params);
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
target[key](...params);
|
|
472
|
+
}
|
|
473
|
+
return target;
|
|
474
|
+
};
|
|
475
|
+
} else {
|
|
476
|
+
return Reflect.get(target, key, receiver);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
481
|
+
if (props.debug) {
|
|
482
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
310
483
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
config2.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
484
|
+
const watchDataProp = (dataProp) => {
|
|
485
|
+
var _a3, _b3, _c3, _d2;
|
|
486
|
+
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
487
|
+
callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
|
|
488
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
489
|
+
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
|
|
490
|
+
}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
|
|
491
|
+
};
|
|
492
|
+
if (context.attrs["data:log"]) {
|
|
493
|
+
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
494
|
+
}
|
|
495
|
+
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
496
|
+
var _a4;
|
|
497
|
+
if (typeof config2.callback === "function") {
|
|
498
|
+
model.replaceData((_a4 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a4 : after);
|
|
324
499
|
} else {
|
|
325
|
-
|
|
500
|
+
model.replaceData(after);
|
|
326
501
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
502
|
+
}, config2.options);
|
|
503
|
+
};
|
|
504
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
505
|
+
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
506
|
+
callback: context.attrs["onUpdate:model"],
|
|
507
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
508
|
+
deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
|
|
509
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_c2 = context.attrs["onUpdate:model"]) != null ? _c2 : {}).options)
|
|
510
|
+
} : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
|
|
511
|
+
if (context.attrs["model:log"]) {
|
|
512
|
+
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
329
513
|
}
|
|
514
|
+
(0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
515
|
+
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
516
|
+
}, config2.options);
|
|
330
517
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
518
|
+
if (props.beta) {
|
|
519
|
+
const isRefData = (0, import_vue.isRef)(props.data);
|
|
520
|
+
if (isRefData || isFunctionData || isPromiseData) {
|
|
521
|
+
setTimeout(async () => {
|
|
522
|
+
var _a3, _b3, _c3;
|
|
523
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
524
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
525
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
526
|
+
]) : [props.data];
|
|
527
|
+
(0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
528
|
+
var _a4;
|
|
529
|
+
if (before !== void 0 || after !== void 0) {
|
|
530
|
+
const callback = context.attrs["data:callback"];
|
|
531
|
+
if (typeof callback === "function") {
|
|
532
|
+
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
533
|
+
model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
|
|
534
|
+
} else {
|
|
535
|
+
model.replaceData(after);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}, {
|
|
539
|
+
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
540
|
+
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
541
|
+
once: context.attrs["data:once"]
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
}
|
|
338
545
|
} else {
|
|
339
|
-
|
|
546
|
+
setTimeout(async () => {
|
|
547
|
+
var _a3;
|
|
548
|
+
const [data] = await Promise.all([
|
|
549
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
550
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
551
|
+
]);
|
|
552
|
+
watchDataProp(data);
|
|
553
|
+
});
|
|
340
554
|
}
|
|
555
|
+
setTimeout(async () => {
|
|
556
|
+
var _a3;
|
|
557
|
+
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
558
|
+
});
|
|
559
|
+
component.value = [access(component)].reduce((options, parent) => {
|
|
560
|
+
var _a3;
|
|
561
|
+
while (parent) {
|
|
562
|
+
if (typeof parent.setup === "function") {
|
|
563
|
+
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
564
|
+
if (access(parent.$parent).ReactiveView) {
|
|
565
|
+
break;
|
|
566
|
+
} else {
|
|
567
|
+
parent = access(parent.$parent);
|
|
568
|
+
}
|
|
569
|
+
} else {
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return options;
|
|
574
|
+
}, component.value);
|
|
575
|
+
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
576
|
+
return (vue2) => {
|
|
577
|
+
var _a3, _b3;
|
|
578
|
+
if (isReady.value) {
|
|
579
|
+
return access(component).template(component, vue2);
|
|
580
|
+
} else {
|
|
581
|
+
return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
|
|
582
|
+
}
|
|
583
|
+
};
|
|
341
584
|
};
|
|
585
|
+
return props.beta === "next" ? beta() : current();
|
|
342
586
|
}
|
|
343
587
|
};
|
|
344
588
|
|
|
345
589
|
// src/index.ts
|
|
346
590
|
var import_vue2 = require("vue");
|
|
347
591
|
var import_date_fns_tz = require("date-fns-tz");
|
|
592
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
593
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
348
594
|
var index_default = ReactiveView_default;
|
|
349
595
|
function safeRequest(request) {
|
|
350
596
|
return new Promise(async (resolve) => {
|
|
@@ -374,7 +620,7 @@ function safeRequest(request) {
|
|
|
374
620
|
}
|
|
375
621
|
});
|
|
376
622
|
}
|
|
377
|
-
function getProps(props, param2) {
|
|
623
|
+
function getProps(props = {}, param2) {
|
|
378
624
|
var _a;
|
|
379
625
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
380
626
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -418,8 +664,9 @@ function getDate(param1, param2) {
|
|
|
418
664
|
return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
|
|
419
665
|
}
|
|
420
666
|
function access(view = {}, alternative) {
|
|
667
|
+
var _a;
|
|
421
668
|
const resolve = (target) => {
|
|
422
|
-
return new Proxy(target, {
|
|
669
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
423
670
|
get(target2, key) {
|
|
424
671
|
const component = { tree: target2 };
|
|
425
672
|
do {
|
|
@@ -440,9 +687,8 @@ function access(view = {}, alternative) {
|
|
|
440
687
|
});
|
|
441
688
|
};
|
|
442
689
|
try {
|
|
443
|
-
const component = typeof view === "function" ? view() : view;
|
|
444
|
-
|
|
445
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
690
|
+
const component = (_a = (0, import_vue2.unref)(typeof view === "function" ? view() : view)) != null ? _a : {};
|
|
691
|
+
return resolve("instance" in component ? component.instance : component);
|
|
446
692
|
} catch (e) {
|
|
447
693
|
return resolve(view);
|
|
448
694
|
}
|
|
@@ -525,37 +771,125 @@ var extendVnode = (component, element) => {
|
|
|
525
771
|
const vnode = getVnode();
|
|
526
772
|
return (props = {}, slots) => {
|
|
527
773
|
var _a;
|
|
528
|
-
const
|
|
529
|
-
const
|
|
774
|
+
const isFunctionClass = typeof props.class === "function";
|
|
775
|
+
const isFunctionStyle = typeof props.style === "function";
|
|
776
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
777
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
778
|
+
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
530
779
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
].includes(key2) && typeof value === "function") {
|
|
535
|
-
props2[key2] = value(vnode.props[key2]);
|
|
780
|
+
var _a2;
|
|
781
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
782
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
536
783
|
}
|
|
537
784
|
return props2;
|
|
538
785
|
}, props);
|
|
539
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
544
|
-
return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
786
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
787
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
788
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
789
|
+
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
545
790
|
};
|
|
546
791
|
}
|
|
547
792
|
});
|
|
548
793
|
};
|
|
794
|
+
function defineReactiveView(param1, param2) {
|
|
795
|
+
const instance = (0, import_vue2.ref)();
|
|
796
|
+
return (0, import_vue2.defineComponent)({
|
|
797
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
798
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
799
|
+
setup() {
|
|
800
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
801
|
+
return (component) => {
|
|
802
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
803
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
804
|
+
}, {});
|
|
805
|
+
const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
|
|
806
|
+
return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
807
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
808
|
+
} : {})), {
|
|
809
|
+
instance
|
|
810
|
+
}), slots);
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
function showComponent(component, options = {}) {
|
|
816
|
+
var _a;
|
|
817
|
+
if (options.router) {
|
|
818
|
+
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
819
|
+
}
|
|
820
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
821
|
+
const container = options.container || "app-dialogs";
|
|
822
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
823
|
+
if (!dialogs.hasAttribute("id")) {
|
|
824
|
+
dialogs.setAttribute("id", container);
|
|
825
|
+
document.body.appendChild(dialogs);
|
|
826
|
+
}
|
|
827
|
+
const dialog = document.createElement("div");
|
|
828
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
829
|
+
dialog.setAttribute("id", id);
|
|
830
|
+
dialogs.appendChild(dialog);
|
|
831
|
+
const app = (0, import_vue2.createApp)(
|
|
832
|
+
{
|
|
833
|
+
setup() {
|
|
834
|
+
return () => component;
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
__cleanup__: () => {
|
|
839
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
840
|
+
app.unmount();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
);
|
|
844
|
+
if (options.router) {
|
|
845
|
+
return app.use(options.router).mount(`#${id}`);
|
|
846
|
+
} else if (options.plugins) {
|
|
847
|
+
return options.plugins.reduce((app2, plugin) => {
|
|
848
|
+
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
849
|
+
}, app).mount(`#${id}`);
|
|
850
|
+
} else {
|
|
851
|
+
return app.mount(`#${id}`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
var getData = (component, path, alternative) => {
|
|
856
|
+
const vue = access(component);
|
|
857
|
+
const data = import_object_manager2.default.on(componentState(vue));
|
|
858
|
+
if (path) {
|
|
859
|
+
return data.get(dataPath(vue, path), alternative);
|
|
860
|
+
} else {
|
|
861
|
+
return data.get();
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var setData = (component, data, path) => {
|
|
865
|
+
const vue = access(component);
|
|
866
|
+
const diff = {
|
|
867
|
+
before: import_object_manager2.default.on(componentState(vue)).clone(),
|
|
868
|
+
after: path ? import_object_manager2.default.on(componentState(vue)).set(dataPath(vue, path), data).get() : import_object_manager2.default.on(componentState(vue)).set(data).get()
|
|
869
|
+
};
|
|
870
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
871
|
+
};
|
|
872
|
+
var componentState = (component) => {
|
|
873
|
+
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
874
|
+
};
|
|
875
|
+
var dataPath = (component, path) => {
|
|
876
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
877
|
+
};
|
|
549
878
|
// Annotate the CommonJS export names for ESM import in node:
|
|
550
879
|
0 && (module.exports = {
|
|
551
880
|
MergeStyles,
|
|
552
881
|
StyleParser,
|
|
553
882
|
access,
|
|
883
|
+
dataPath,
|
|
884
|
+
defineReactiveView,
|
|
554
885
|
extendVnode,
|
|
886
|
+
getData,
|
|
555
887
|
getDate,
|
|
556
888
|
getProps,
|
|
557
889
|
getReactiveViewComponent,
|
|
558
890
|
safeRequest,
|
|
891
|
+
setData,
|
|
559
892
|
setup,
|
|
893
|
+
showComponent,
|
|
560
894
|
useSubscription
|
|
561
895
|
});
|