@razaman2/reactive-view 0.0.34-beta.9 → 0.1.0-beta.1
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 +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.js +413 -120
- package/dist/index.mjs +413 -122
- package/package.json +48 -47
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
var __objRest = (source, exclude) => {
|
|
18
21
|
var target = {};
|
|
19
22
|
for (var prop in source)
|
|
@@ -124,11 +127,11 @@ var Subscriptions = _Subscriptions;
|
|
|
124
127
|
// src/ReactiveView.ts
|
|
125
128
|
import ObjectManager from "@razaman2/object-manager";
|
|
126
129
|
import DataManager from "@razaman2/data-manager";
|
|
127
|
-
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
|
|
130
|
+
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance, unref } from "vue";
|
|
128
131
|
|
|
129
132
|
// package.json
|
|
130
133
|
var name = "@razaman2/reactive-view";
|
|
131
|
-
var version = "0.0
|
|
134
|
+
var version = "0.1.0-beta.1";
|
|
132
135
|
|
|
133
136
|
// src/ReactiveView.ts
|
|
134
137
|
var setup = {
|
|
@@ -139,19 +142,16 @@ var setup = {
|
|
|
139
142
|
var ReactiveView_default = {
|
|
140
143
|
props: {
|
|
141
144
|
setup: {},
|
|
145
|
+
beta: [Boolean, String],
|
|
142
146
|
ReactiveView: {
|
|
143
147
|
type: Boolean,
|
|
144
148
|
default: true
|
|
145
149
|
},
|
|
146
|
-
instance: {
|
|
147
|
-
default: () => ref()
|
|
148
|
-
},
|
|
150
|
+
instance: { default: ref() },
|
|
149
151
|
notifications: Object,
|
|
150
152
|
subscriptions: Object,
|
|
151
153
|
beforeSetData: Function,
|
|
152
|
-
data: {
|
|
153
|
-
default: () => ({})
|
|
154
|
-
},
|
|
154
|
+
data: { default: reactive({}) },
|
|
155
155
|
defaultData: {},
|
|
156
156
|
getDefaultData: {
|
|
157
157
|
type: Function,
|
|
@@ -172,18 +172,21 @@ var ReactiveView_default = {
|
|
|
172
172
|
type: Boolean,
|
|
173
173
|
default: false
|
|
174
174
|
},
|
|
175
|
-
state: {}
|
|
175
|
+
state: { default: reactive({}) }
|
|
176
176
|
},
|
|
177
177
|
setup(props, context) {
|
|
178
|
-
var _a, _b, _c
|
|
178
|
+
var _a, _b, _c;
|
|
179
179
|
const diff = (before, after) => {
|
|
180
|
-
const
|
|
180
|
+
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
181
|
+
let changed = false;
|
|
182
|
+
const change = paths.reduce((change2, path) => {
|
|
181
183
|
if (before.get(path) !== after.get(path)) {
|
|
182
184
|
change2.set(path, after.get(path));
|
|
185
|
+
changed = true;
|
|
183
186
|
}
|
|
184
187
|
return change2;
|
|
185
188
|
}, ObjectManager.on({}));
|
|
186
|
-
return { before: before.get(), after: after.get(),
|
|
189
|
+
return { before: before.get(), after: after.get(), changes: change.get(), changed };
|
|
187
190
|
};
|
|
188
191
|
const dataPath2 = (path) => {
|
|
189
192
|
try {
|
|
@@ -192,140 +195,348 @@ var ReactiveView_default = {
|
|
|
192
195
|
return path;
|
|
193
196
|
}
|
|
194
197
|
};
|
|
195
|
-
const template = (
|
|
196
|
-
return createVNode(
|
|
197
|
-
"
|
|
198
|
-
|
|
199
|
-
style: { color: "red", textAlign: "center" }
|
|
200
|
-
}, context.attrs),
|
|
201
|
-
context.slots.default ? context.slots.default({ component: component2, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`
|
|
202
|
-
);
|
|
198
|
+
const template = (component, vue2) => {
|
|
199
|
+
return createVNode("div", context.slots.default ? context.attrs : __spreadValues({
|
|
200
|
+
style: { color: "red", textAlign: "center" }
|
|
201
|
+
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
|
|
203
202
|
};
|
|
204
203
|
const isValid = ref(false);
|
|
205
204
|
const isReady = ref(false);
|
|
205
|
+
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
206
206
|
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
207
207
|
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
208
208
|
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
209
|
-
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
210
209
|
const vue = getCurrentInstance();
|
|
211
|
-
if ((
|
|
212
|
-
console.
|
|
210
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
211
|
+
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
213
212
|
}
|
|
214
213
|
const defaultData = props.getDefaultData(
|
|
215
|
-
|
|
214
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
|
|
216
215
|
);
|
|
217
216
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
217
|
+
const beta = () => {
|
|
218
|
+
var _a2;
|
|
219
|
+
const emit = (after, before) => {
|
|
220
|
+
if (vue && vue.vnode.el) {
|
|
221
|
+
const event = new CustomEvent("data:emit", {
|
|
222
|
+
bubbles: true,
|
|
223
|
+
// Key: allows it to travel up
|
|
224
|
+
composed: true,
|
|
225
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
226
|
+
detail: { before, after }
|
|
227
|
+
// Payload goes here
|
|
228
|
+
});
|
|
229
|
+
access(component).model.setData(after);
|
|
230
|
+
vue.vnode.el.dispatchEvent(event);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const proxy = (data) => {
|
|
234
|
+
return new Proxy(data, {
|
|
235
|
+
get(target, key, receiver) {
|
|
236
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
237
|
+
return (...params) => {
|
|
238
|
+
var _a3;
|
|
239
|
+
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
240
|
+
if (typeof beforeSetData === "function") {
|
|
241
|
+
const before = ObjectManager.on(target.getData());
|
|
242
|
+
const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
|
|
243
|
+
const diff2 = access(component).diff(before, after);
|
|
244
|
+
if (beforeSetData(diff2, target)) {
|
|
245
|
+
target[key](...params);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
target[key](...params);
|
|
249
|
+
}
|
|
250
|
+
return target;
|
|
251
|
+
};
|
|
240
252
|
} else {
|
|
241
|
-
target
|
|
253
|
+
return Reflect.get(target, key, receiver);
|
|
242
254
|
}
|
|
243
|
-
|
|
244
|
-
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const normalize = (data) => {
|
|
259
|
+
const datatype2 = Array.isArray(defaultData) ? [] : {};
|
|
260
|
+
if (isRef(data) || isReactive(data) || isFunctionData || isPromiseData) {
|
|
261
|
+
return reactive(datatype2);
|
|
245
262
|
} else {
|
|
246
|
-
|
|
263
|
+
const props2 = "data" in vue.vnode.props;
|
|
264
|
+
try {
|
|
265
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
266
|
+
return reactive(datatype2);
|
|
267
|
+
} else {
|
|
268
|
+
return reactive(props2 ? { "": datatype2 } : datatype2);
|
|
269
|
+
}
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return reactive(props2 ? { "": datatype2 } : datatype2);
|
|
272
|
+
}
|
|
247
273
|
}
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
const component = ref({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
|
|
251
|
-
if (props.debug) {
|
|
252
|
-
console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
253
|
-
}
|
|
254
|
-
const watchDataProp = (dataProp) => {
|
|
255
|
-
var _a2, _b2, _c2, _d2;
|
|
256
|
-
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
257
|
-
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
258
|
-
options: Object.assign(__spreadValues(__spreadValues({
|
|
259
|
-
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
260
|
-
}, 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)
|
|
261
274
|
};
|
|
262
|
-
|
|
263
|
-
|
|
275
|
+
const config = {
|
|
276
|
+
data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
|
|
277
|
+
defaultData: ObjectManager.on(defaultData).clone(),
|
|
278
|
+
notifications: props.notifications,
|
|
279
|
+
subscriptions: props.subscriptions,
|
|
280
|
+
name: props.modelName,
|
|
281
|
+
logging: props.logging
|
|
282
|
+
};
|
|
283
|
+
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config);
|
|
284
|
+
const component = ref({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
285
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
286
|
+
const config2 = {
|
|
287
|
+
callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
|
|
288
|
+
options: {
|
|
289
|
+
immediate: context.attrs["model:immediate"],
|
|
290
|
+
deep: context.attrs["model:deep"],
|
|
291
|
+
once: context.attrs["model:once"]
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const source = () => ObjectManager.on(model.getData()).clone();
|
|
295
|
+
watch(source, (after, before) => {
|
|
296
|
+
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
297
|
+
if (diff2.changed) {
|
|
298
|
+
config2.callback(diff2, { component });
|
|
299
|
+
}
|
|
300
|
+
});
|
|
264
301
|
}
|
|
265
|
-
|
|
302
|
+
setTimeout(async () => {
|
|
303
|
+
var _a3, _b2, _c2;
|
|
304
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
305
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
306
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
307
|
+
]) : [props.data];
|
|
308
|
+
const isRefData = isRef(data);
|
|
309
|
+
const isReactiveData = isReactive(data);
|
|
310
|
+
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
311
|
+
watch(source, async (after, before) => {
|
|
312
|
+
var _a4;
|
|
313
|
+
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
314
|
+
const callback = context.attrs["data:callback"];
|
|
315
|
+
if (typeof callback === "function") {
|
|
316
|
+
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
317
|
+
} else {
|
|
318
|
+
model.replaceData(after);
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
322
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
323
|
+
once: context.attrs["data:once"]
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
setTimeout(async () => {
|
|
266
327
|
var _a3;
|
|
267
|
-
|
|
268
|
-
|
|
328
|
+
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
329
|
+
});
|
|
330
|
+
component.value = [access(component)].reduce((options, parent) => {
|
|
331
|
+
var _a3;
|
|
332
|
+
while (parent) {
|
|
333
|
+
if (typeof parent.setup === "function") {
|
|
334
|
+
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
335
|
+
if (access(parent.$parent).ReactiveView) {
|
|
336
|
+
break;
|
|
337
|
+
} else {
|
|
338
|
+
parent = access(parent.$parent);
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return options;
|
|
345
|
+
}, component.value);
|
|
346
|
+
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
347
|
+
return (vue2) => {
|
|
348
|
+
var _a3, _b2;
|
|
349
|
+
if (isReady.value) {
|
|
350
|
+
return access(component).template(component, vue2);
|
|
269
351
|
} else {
|
|
270
|
-
|
|
352
|
+
return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
|
|
271
353
|
}
|
|
272
|
-
}
|
|
354
|
+
};
|
|
273
355
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
356
|
+
const current = () => {
|
|
357
|
+
var _a2, _b2, _c2, _d;
|
|
358
|
+
const emit = (after, before) => {
|
|
359
|
+
if (vue && vue.vnode.el) {
|
|
360
|
+
const event = new CustomEvent("data:emit", {
|
|
361
|
+
bubbles: true,
|
|
362
|
+
// Key: allows it to travel up
|
|
363
|
+
composed: true,
|
|
364
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
365
|
+
detail: { before, after }
|
|
366
|
+
// Payload goes here
|
|
367
|
+
});
|
|
368
|
+
vue.vnode.el.dispatchEvent(event);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const normalize = (data) => {
|
|
372
|
+
if (props.debug) {
|
|
373
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
|
|
374
|
+
}
|
|
375
|
+
if (isReactive(data)) {
|
|
376
|
+
return data;
|
|
377
|
+
} else {
|
|
378
|
+
if (isRef(data) || isFunctionData || isPromiseData) {
|
|
379
|
+
return reactive(datatype);
|
|
380
|
+
} else {
|
|
381
|
+
const props2 = "data" in vue.vnode.props;
|
|
382
|
+
try {
|
|
383
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
384
|
+
return reactive(props2 ? data : datatype);
|
|
385
|
+
} else {
|
|
386
|
+
return reactive(props2 ? { "": data } : datatype);
|
|
387
|
+
}
|
|
388
|
+
} catch (e) {
|
|
389
|
+
return reactive(props2 ? { "": data } : datatype);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const config = {
|
|
395
|
+
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
|
|
396
|
+
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
397
|
+
).clone()),
|
|
398
|
+
defaultData: ObjectManager.on(defaultData).clone(),
|
|
399
|
+
notifications: props.notifications,
|
|
400
|
+
subscriptions: props.subscriptions,
|
|
401
|
+
name: props.modelName,
|
|
402
|
+
logging: props.logging
|
|
403
|
+
};
|
|
404
|
+
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
|
|
405
|
+
get(target, key, receiver) {
|
|
406
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
407
|
+
return (...params) => {
|
|
408
|
+
var _a3;
|
|
409
|
+
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
410
|
+
if (typeof beforeSetData === "function") {
|
|
411
|
+
const before = ObjectManager.on(target.getData());
|
|
412
|
+
const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
|
|
413
|
+
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
414
|
+
target[key](...params);
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
target[key](...params);
|
|
418
|
+
}
|
|
419
|
+
return target;
|
|
420
|
+
};
|
|
421
|
+
} else {
|
|
422
|
+
return Reflect.get(target, key, receiver);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
427
|
+
if (props.debug) {
|
|
428
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
283
429
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
while (parent) {
|
|
300
|
-
if (typeof parent.setup === "function") {
|
|
301
|
-
options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
|
|
302
|
-
if (access(parent.$parent).ReactiveView) {
|
|
303
|
-
break;
|
|
430
|
+
const watchDataProp = (dataProp) => {
|
|
431
|
+
var _a3, _b3, _c3, _d2;
|
|
432
|
+
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
433
|
+
callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
|
|
434
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
435
|
+
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
|
|
436
|
+
}, 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)
|
|
437
|
+
};
|
|
438
|
+
if (context.attrs["data:log"]) {
|
|
439
|
+
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
440
|
+
}
|
|
441
|
+
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
442
|
+
var _a4;
|
|
443
|
+
if (typeof config2.callback === "function") {
|
|
444
|
+
model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
|
|
304
445
|
} else {
|
|
305
|
-
|
|
446
|
+
model.replaceData(after);
|
|
306
447
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
448
|
+
}, config2.options);
|
|
449
|
+
};
|
|
450
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
451
|
+
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
452
|
+
callback: context.attrs["onUpdate:model"],
|
|
453
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
454
|
+
deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
|
|
455
|
+
}, 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)
|
|
456
|
+
} : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
|
|
457
|
+
if (context.attrs["model:log"]) {
|
|
458
|
+
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
309
459
|
}
|
|
460
|
+
watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
461
|
+
config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
462
|
+
}, config2.options);
|
|
310
463
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
464
|
+
if (props.beta) {
|
|
465
|
+
const isRefData = isRef(props.data);
|
|
466
|
+
if (isRefData || isFunctionData || isPromiseData) {
|
|
467
|
+
setTimeout(async () => {
|
|
468
|
+
var _a3, _b3, _c3;
|
|
469
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
470
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
471
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
472
|
+
]) : [props.data];
|
|
473
|
+
watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
474
|
+
var _a4;
|
|
475
|
+
if (before !== void 0 || after !== void 0) {
|
|
476
|
+
const callback = context.attrs["data:callback"];
|
|
477
|
+
if (typeof callback === "function") {
|
|
478
|
+
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
479
|
+
model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
|
|
480
|
+
} else {
|
|
481
|
+
model.replaceData(after);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}, {
|
|
485
|
+
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
486
|
+
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
487
|
+
once: context.attrs["data:once"]
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
318
491
|
} else {
|
|
319
|
-
|
|
492
|
+
setTimeout(async () => {
|
|
493
|
+
var _a3;
|
|
494
|
+
const [data] = await Promise.all([
|
|
495
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
496
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
497
|
+
]);
|
|
498
|
+
watchDataProp(data);
|
|
499
|
+
});
|
|
320
500
|
}
|
|
501
|
+
setTimeout(async () => {
|
|
502
|
+
var _a3;
|
|
503
|
+
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
504
|
+
});
|
|
505
|
+
component.value = [access(component)].reduce((options, parent) => {
|
|
506
|
+
var _a3;
|
|
507
|
+
while (parent) {
|
|
508
|
+
if (typeof parent.setup === "function") {
|
|
509
|
+
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
510
|
+
if (access(parent.$parent).ReactiveView) {
|
|
511
|
+
break;
|
|
512
|
+
} else {
|
|
513
|
+
parent = access(parent.$parent);
|
|
514
|
+
}
|
|
515
|
+
} else {
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return options;
|
|
520
|
+
}, component.value);
|
|
521
|
+
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
522
|
+
return (vue2) => {
|
|
523
|
+
var _a3, _b3;
|
|
524
|
+
if (isReady.value) {
|
|
525
|
+
return access(component).template(component, vue2);
|
|
526
|
+
} else {
|
|
527
|
+
return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
|
|
528
|
+
}
|
|
529
|
+
};
|
|
321
530
|
};
|
|
531
|
+
return props.beta === "next" ? beta() : current();
|
|
322
532
|
}
|
|
323
533
|
};
|
|
324
534
|
|
|
325
535
|
// src/index.ts
|
|
326
|
-
import { h,
|
|
536
|
+
import { h, ref as ref2, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
|
|
327
537
|
import { formatInTimeZone } from "date-fns-tz";
|
|
328
538
|
import { twMerge } from "tailwind-merge";
|
|
539
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
329
540
|
var index_default = ReactiveView_default;
|
|
330
541
|
function safeRequest(request) {
|
|
331
542
|
return new Promise(async (resolve) => {
|
|
@@ -399,6 +610,7 @@ function getDate(param1, param2) {
|
|
|
399
610
|
return formatInTimeZone(datetime(), options.timezone, options.format);
|
|
400
611
|
}
|
|
401
612
|
function access(view = {}, alternative) {
|
|
613
|
+
var _a;
|
|
402
614
|
const resolve = (target) => {
|
|
403
615
|
return new Proxy(toRaw(target), {
|
|
404
616
|
get(target2, key) {
|
|
@@ -421,9 +633,8 @@ function access(view = {}, alternative) {
|
|
|
421
633
|
});
|
|
422
634
|
};
|
|
423
635
|
try {
|
|
424
|
-
const component = typeof view === "function" ? view() : view;
|
|
425
|
-
|
|
426
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
636
|
+
const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
|
|
637
|
+
return resolve("instance" in component ? component.instance : component);
|
|
427
638
|
} catch (e) {
|
|
428
639
|
return resolve(view);
|
|
429
640
|
}
|
|
@@ -506,28 +717,106 @@ var extendVnode = (component, element) => {
|
|
|
506
717
|
const vnode = getVnode();
|
|
507
718
|
return (props = {}, slots) => {
|
|
508
719
|
var _a;
|
|
509
|
-
const
|
|
510
|
-
const
|
|
511
|
-
const
|
|
720
|
+
const isFunctionClass = typeof props.class === "function";
|
|
721
|
+
const isFunctionStyle = typeof props.style === "function";
|
|
722
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
723
|
+
const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
724
|
+
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
512
725
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
513
726
|
var _a2;
|
|
514
|
-
if (!["class", "style"].includes(key2) && typeof value === "function") {
|
|
727
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
515
728
|
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
516
729
|
}
|
|
517
730
|
return props2;
|
|
518
731
|
}, props);
|
|
519
732
|
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
520
733
|
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
521
|
-
|
|
734
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
735
|
+
return h(finalElement, finalProps, finalSlots);
|
|
522
736
|
};
|
|
523
737
|
}
|
|
524
738
|
});
|
|
525
739
|
};
|
|
740
|
+
function defineReactiveView(param1, param2) {
|
|
741
|
+
const instance = ref2();
|
|
742
|
+
return defineComponent({
|
|
743
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
744
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
745
|
+
setup() {
|
|
746
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
747
|
+
return (component) => {
|
|
748
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
749
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
750
|
+
}, {});
|
|
751
|
+
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;
|
|
752
|
+
return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
753
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
754
|
+
} : {})), {
|
|
755
|
+
instance
|
|
756
|
+
}), slots);
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
function showComponent(component, options = {}) {
|
|
762
|
+
var _a;
|
|
763
|
+
if (options.router) {
|
|
764
|
+
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
765
|
+
}
|
|
766
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
767
|
+
const container = options.container || "app-dialogs";
|
|
768
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
769
|
+
if (!dialogs.hasAttribute("id")) {
|
|
770
|
+
dialogs.setAttribute("id", container);
|
|
771
|
+
document.body.appendChild(dialogs);
|
|
772
|
+
}
|
|
773
|
+
const dialog = document.createElement("div");
|
|
774
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
775
|
+
dialog.setAttribute("id", id);
|
|
776
|
+
dialogs.appendChild(dialog);
|
|
777
|
+
const app = createApp(
|
|
778
|
+
{
|
|
779
|
+
setup() {
|
|
780
|
+
return () => component;
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
__cleanup__: () => {
|
|
785
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
786
|
+
app.unmount();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
);
|
|
790
|
+
if (options.router) {
|
|
791
|
+
return app.use(options.router).mount(`#${id}`);
|
|
792
|
+
} else if (options.plugins) {
|
|
793
|
+
return options.plugins.reduce((app2, plugin) => {
|
|
794
|
+
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
795
|
+
}, app).mount(`#${id}`);
|
|
796
|
+
} else {
|
|
797
|
+
return app.mount(`#${id}`);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
526
801
|
var getData = (component, path, alternative) => {
|
|
527
|
-
|
|
802
|
+
const vue = access(component);
|
|
803
|
+
const data = ObjectManager2.on(componentState(vue));
|
|
804
|
+
if (path) {
|
|
805
|
+
return data.get(dataPath(vue, path), alternative);
|
|
806
|
+
} else {
|
|
807
|
+
return data.get();
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var setData = (component, data, path) => {
|
|
811
|
+
const vue = access(component);
|
|
812
|
+
const diff = {
|
|
813
|
+
before: ObjectManager2.on(componentState(vue)).clone(),
|
|
814
|
+
after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
|
|
815
|
+
};
|
|
816
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
528
817
|
};
|
|
529
|
-
var
|
|
530
|
-
return
|
|
818
|
+
var componentState = (component) => {
|
|
819
|
+
return unref2("state" in component ? component.state : component.$attrs.state);
|
|
531
820
|
};
|
|
532
821
|
var dataPath = (component, path) => {
|
|
533
822
|
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
@@ -538,6 +827,7 @@ export {
|
|
|
538
827
|
access,
|
|
539
828
|
dataPath,
|
|
540
829
|
index_default as default,
|
|
830
|
+
defineReactiveView,
|
|
541
831
|
extendVnode,
|
|
542
832
|
getData,
|
|
543
833
|
getDate,
|
|
@@ -546,5 +836,6 @@ export {
|
|
|
546
836
|
safeRequest,
|
|
547
837
|
setData,
|
|
548
838
|
setup,
|
|
839
|
+
showComponent,
|
|
549
840
|
useSubscription
|
|
550
841
|
};
|