@razaman2/reactive-view 0.0.34-beta.3 → 0.0.34-beta.31
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 +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +241 -60
- package/dist/index.mjs +240 -62
- package/package.json +48 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
|
|
2
|
+
import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
|
|
3
3
|
|
|
4
4
|
type ComponentExtension = {
|
|
5
5
|
parent?: ComponentExtension;
|
|
@@ -43,12 +43,13 @@ declare const setup: {
|
|
|
43
43
|
declare const _default: {
|
|
44
44
|
props: {
|
|
45
45
|
setup: {};
|
|
46
|
+
beta: BooleanConstructor;
|
|
46
47
|
ReactiveView: {
|
|
47
48
|
type: BooleanConstructor;
|
|
48
49
|
default: boolean;
|
|
49
50
|
};
|
|
50
51
|
instance: {
|
|
51
|
-
default:
|
|
52
|
+
default: vue.Ref<any, any>;
|
|
52
53
|
};
|
|
53
54
|
notifications: ObjectConstructor;
|
|
54
55
|
subscriptions: ObjectConstructor;
|
|
@@ -74,6 +75,9 @@ declare const _default: {
|
|
|
74
75
|
type: BooleanConstructor;
|
|
75
76
|
default: boolean;
|
|
76
77
|
};
|
|
78
|
+
state: {
|
|
79
|
+
default: () => {};
|
|
80
|
+
};
|
|
77
81
|
};
|
|
78
82
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
79
83
|
};
|
|
@@ -117,5 +121,17 @@ declare function useSubscription(): {
|
|
|
117
121
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
118
122
|
declare function MergeStyles(...params: any): any;
|
|
119
123
|
declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
|
|
124
|
+
declare function defineReactiveView(): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
126
|
+
declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
|
|
127
|
+
declare function showComponent(component: any, options?: {
|
|
128
|
+
container?: string;
|
|
129
|
+
key?: string;
|
|
130
|
+
router?: any;
|
|
131
|
+
plugins?: Array<any>;
|
|
132
|
+
}): any;
|
|
133
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
134
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
135
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
120
136
|
|
|
121
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
137
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
|
|
2
|
+
import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
|
|
3
3
|
|
|
4
4
|
type ComponentExtension = {
|
|
5
5
|
parent?: ComponentExtension;
|
|
@@ -43,12 +43,13 @@ declare const setup: {
|
|
|
43
43
|
declare const _default: {
|
|
44
44
|
props: {
|
|
45
45
|
setup: {};
|
|
46
|
+
beta: BooleanConstructor;
|
|
46
47
|
ReactiveView: {
|
|
47
48
|
type: BooleanConstructor;
|
|
48
49
|
default: boolean;
|
|
49
50
|
};
|
|
50
51
|
instance: {
|
|
51
|
-
default:
|
|
52
|
+
default: vue.Ref<any, any>;
|
|
52
53
|
};
|
|
53
54
|
notifications: ObjectConstructor;
|
|
54
55
|
subscriptions: ObjectConstructor;
|
|
@@ -74,6 +75,9 @@ declare const _default: {
|
|
|
74
75
|
type: BooleanConstructor;
|
|
75
76
|
default: boolean;
|
|
76
77
|
};
|
|
78
|
+
state: {
|
|
79
|
+
default: () => {};
|
|
80
|
+
};
|
|
77
81
|
};
|
|
78
82
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
79
83
|
};
|
|
@@ -117,5 +121,17 @@ declare function useSubscription(): {
|
|
|
117
121
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
118
122
|
declare function MergeStyles(...params: any): any;
|
|
119
123
|
declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
|
|
124
|
+
declare function defineReactiveView(): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
126
|
+
declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
|
|
127
|
+
declare function showComponent(component: any, options?: {
|
|
128
|
+
container?: string;
|
|
129
|
+
key?: string;
|
|
130
|
+
router?: any;
|
|
131
|
+
plugins?: Array<any>;
|
|
132
|
+
}): any;
|
|
133
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
134
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
135
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
120
136
|
|
|
121
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
137
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
|
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.34-beta.
|
|
180
|
+
var version = "0.0.34-beta.31";
|
|
172
181
|
|
|
173
182
|
// src/ReactiveView.ts
|
|
174
183
|
var setup = {
|
|
@@ -179,19 +188,16 @@ var setup = {
|
|
|
179
188
|
var ReactiveView_default = {
|
|
180
189
|
props: {
|
|
181
190
|
setup: {},
|
|
191
|
+
beta: Boolean,
|
|
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: {
|
|
193
|
-
default: () => ({})
|
|
194
|
-
},
|
|
200
|
+
data: { default: () => (0, import_vue.reactive)({}) },
|
|
195
201
|
defaultData: {},
|
|
196
202
|
getDefaultData: {
|
|
197
203
|
type: Function,
|
|
@@ -211,10 +217,27 @@ var ReactiveView_default = {
|
|
|
211
217
|
debug: {
|
|
212
218
|
type: Boolean,
|
|
213
219
|
default: false
|
|
214
|
-
}
|
|
220
|
+
},
|
|
221
|
+
state: { default: () => (0, import_vue.reactive)({}) }
|
|
215
222
|
},
|
|
216
223
|
setup(props, context) {
|
|
217
|
-
var _a, _b, _c, _d, _e, _f;
|
|
224
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
225
|
+
const diff = (before, after) => {
|
|
226
|
+
const change = after.paths().reduce((change2, path) => {
|
|
227
|
+
if (before.get(path) !== after.get(path)) {
|
|
228
|
+
change2.set(path, after.get(path));
|
|
229
|
+
}
|
|
230
|
+
return change2;
|
|
231
|
+
}, import_object_manager.default.on({}));
|
|
232
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
233
|
+
};
|
|
234
|
+
const dataPath2 = (path) => {
|
|
235
|
+
try {
|
|
236
|
+
return context.attrs["data:path"](path);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
return path;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
218
241
|
const template = (component2, vue2) => {
|
|
219
242
|
return (0, import_vue.createVNode)(
|
|
220
243
|
"div",
|
|
@@ -226,38 +249,74 @@ var ReactiveView_default = {
|
|
|
226
249
|
};
|
|
227
250
|
const isValid = (0, import_vue.ref)(false);
|
|
228
251
|
const isReady = (0, import_vue.ref)(false);
|
|
229
|
-
const isFunctionData = ["Function"].includes(props.data.constructor.name);
|
|
230
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes(props.data.constructor.name);
|
|
231
|
-
const isPromiseData = ["Promise"].includes(props.data.constructor.name) || isAsyncFunctionData;
|
|
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;
|
|
232
255
|
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
233
256
|
const vue = (0, import_vue.getCurrentInstance)();
|
|
234
|
-
|
|
235
|
-
|
|
257
|
+
const emit = (after, before) => {
|
|
258
|
+
if (vue && vue.vnode.el) {
|
|
259
|
+
const event = new CustomEvent("data:emit", {
|
|
260
|
+
bubbles: true,
|
|
261
|
+
// Key: allows it to travel up
|
|
262
|
+
composed: true,
|
|
263
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
264
|
+
detail: { before, after }
|
|
265
|
+
// Payload goes here
|
|
266
|
+
});
|
|
267
|
+
vue.vnode.el.dispatchEvent(event);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
271
|
+
console.warn("[ReactiveView]: defaultData is required for promise or async function data.", props.data);
|
|
236
272
|
}
|
|
237
273
|
const defaultData = props.getDefaultData(
|
|
238
|
-
|
|
274
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.isRef)(vue.vnode.props.data) ? (0, import_vue.unref)(vue.vnode.props.data) : vue.vnode.props.data) ? [] : {} : {}
|
|
239
275
|
);
|
|
240
276
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
277
|
+
const normalize = (data) => {
|
|
278
|
+
if (props.debug) {
|
|
279
|
+
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) });
|
|
280
|
+
}
|
|
281
|
+
if ((0, import_vue.isReactive)(data)) {
|
|
282
|
+
return data;
|
|
283
|
+
} else {
|
|
284
|
+
if ((0, import_vue.isRef)(data) || isFunctionData || isPromiseData) {
|
|
285
|
+
return (0, import_vue.reactive)(datatype);
|
|
286
|
+
} else {
|
|
287
|
+
const props2 = "data" in vue.vnode.props;
|
|
288
|
+
try {
|
|
289
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
290
|
+
return (0, import_vue.reactive)(props2 ? data : datatype);
|
|
291
|
+
} else {
|
|
292
|
+
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
241
300
|
const config = {
|
|
242
|
-
data: (0, import_vue.reactive)(import_object_manager.default.on(
|
|
243
|
-
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype :
|
|
301
|
+
data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
302
|
+
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
244
303
|
).clone()),
|
|
245
304
|
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
246
305
|
notifications: props.notifications,
|
|
247
306
|
subscriptions: props.subscriptions,
|
|
248
|
-
|
|
249
|
-
|
|
307
|
+
name: props.modelName,
|
|
308
|
+
logging: props.logging
|
|
250
309
|
};
|
|
251
310
|
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
|
|
252
311
|
get(target, key, receiver) {
|
|
253
|
-
if (
|
|
312
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
254
313
|
return (...params) => {
|
|
255
314
|
var _a2;
|
|
256
315
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
257
316
|
if (typeof beforeSetData === "function") {
|
|
258
|
-
const before = target.getData();
|
|
259
|
-
const after =
|
|
260
|
-
if (beforeSetData(
|
|
317
|
+
const before = import_object_manager.default.on(target.getData());
|
|
318
|
+
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
319
|
+
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
261
320
|
target[key](...params);
|
|
262
321
|
}
|
|
263
322
|
} else {
|
|
@@ -270,24 +329,25 @@ var ReactiveView_default = {
|
|
|
270
329
|
}
|
|
271
330
|
}
|
|
272
331
|
});
|
|
273
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
332
|
+
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
274
333
|
if (props.debug) {
|
|
275
|
-
console.
|
|
334
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
276
335
|
}
|
|
277
336
|
const watchDataProp = (dataProp) => {
|
|
278
|
-
var _a2, _b2, _c2;
|
|
337
|
+
var _a2, _b2, _c2, _d2;
|
|
279
338
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
280
339
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
281
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
340
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
341
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
342
|
+
}, 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)
|
|
282
343
|
};
|
|
283
344
|
if (context.attrs["data:log"]) {
|
|
284
|
-
console.
|
|
345
|
+
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
285
346
|
}
|
|
286
347
|
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
287
348
|
var _a3;
|
|
288
|
-
const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
|
|
289
349
|
if (typeof config2.callback === "function") {
|
|
290
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
350
|
+
model.replaceData((_a3 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
|
|
291
351
|
} else {
|
|
292
352
|
model.replaceData(after);
|
|
293
353
|
}
|
|
@@ -297,22 +357,53 @@ var ReactiveView_default = {
|
|
|
297
357
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
298
358
|
callback: context.attrs["onUpdate:model"],
|
|
299
359
|
options: Object.assign(__spreadValues(__spreadValues({
|
|
300
|
-
deep: (
|
|
301
|
-
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((
|
|
302
|
-
} : (
|
|
360
|
+
deep: (_e = context.attrs["model:deep"]) != null ? _e : true
|
|
361
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
|
|
362
|
+
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
303
363
|
if (context.attrs["model:log"]) {
|
|
304
|
-
console.
|
|
364
|
+
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
305
365
|
}
|
|
306
|
-
(0, import_vue.watch)(() => model.getData(), (after, before) => {
|
|
307
|
-
|
|
308
|
-
config2.callback(diff, { component });
|
|
366
|
+
(0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
367
|
+
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
309
368
|
}, config2.options);
|
|
310
369
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
370
|
+
if (props.beta) {
|
|
371
|
+
const isRefData = (0, import_vue.isRef)(props.data);
|
|
372
|
+
if (isRefData || isFunctionData || isPromiseData) {
|
|
373
|
+
setTimeout(async () => {
|
|
374
|
+
var _a2, _b2, _c2;
|
|
375
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
376
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
377
|
+
(_a2 = defer.value) != null ? _a2 : true
|
|
378
|
+
]) : [props.data];
|
|
379
|
+
(0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
380
|
+
var _a3;
|
|
381
|
+
if (before !== void 0 || after !== void 0) {
|
|
382
|
+
const callback = context.attrs["data:callback"];
|
|
383
|
+
if (typeof callback === "function") {
|
|
384
|
+
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
385
|
+
model.replaceData((_a3 = callback(diff2, { component })) != null ? _a3 : after);
|
|
386
|
+
} else {
|
|
387
|
+
model.replaceData(after);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}, {
|
|
391
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
392
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
393
|
+
once: context.attrs["data:once"]
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
setTimeout(async () => {
|
|
399
|
+
var _a2;
|
|
400
|
+
const [data] = await Promise.all([
|
|
401
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
402
|
+
(_a2 = defer.value) != null ? _a2 : true
|
|
403
|
+
]);
|
|
404
|
+
watchDataProp(data);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
316
407
|
setTimeout(async () => {
|
|
317
408
|
var _a2;
|
|
318
409
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -348,6 +439,8 @@ var ReactiveView_default = {
|
|
|
348
439
|
// src/index.ts
|
|
349
440
|
var import_vue2 = require("vue");
|
|
350
441
|
var import_date_fns_tz = require("date-fns-tz");
|
|
442
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
443
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
351
444
|
var index_default = ReactiveView_default;
|
|
352
445
|
function safeRequest(request) {
|
|
353
446
|
return new Promise(async (resolve) => {
|
|
@@ -377,7 +470,7 @@ function safeRequest(request) {
|
|
|
377
470
|
}
|
|
378
471
|
});
|
|
379
472
|
}
|
|
380
|
-
function getProps(props, param2) {
|
|
473
|
+
function getProps(props = {}, param2) {
|
|
381
474
|
var _a;
|
|
382
475
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
383
476
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -421,8 +514,9 @@ function getDate(param1, param2) {
|
|
|
421
514
|
return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
|
|
422
515
|
}
|
|
423
516
|
function access(view = {}, alternative) {
|
|
517
|
+
var _a;
|
|
424
518
|
const resolve = (target) => {
|
|
425
|
-
return new Proxy(target, {
|
|
519
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
426
520
|
get(target2, key) {
|
|
427
521
|
const component = { tree: target2 };
|
|
428
522
|
do {
|
|
@@ -443,9 +537,8 @@ function access(view = {}, alternative) {
|
|
|
443
537
|
});
|
|
444
538
|
};
|
|
445
539
|
try {
|
|
446
|
-
const component = typeof view === "function" ? view() : view;
|
|
447
|
-
|
|
448
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
540
|
+
const component = (_a = (0, import_vue2.unref)(typeof view === "function" ? view() : view)) != null ? _a : {};
|
|
541
|
+
return resolve("instance" in component ? component.instance : component);
|
|
449
542
|
} catch (e) {
|
|
450
543
|
return resolve(view);
|
|
451
544
|
}
|
|
@@ -528,37 +621,125 @@ var extendVnode = (component, element) => {
|
|
|
528
621
|
const vnode = getVnode();
|
|
529
622
|
return (props = {}, slots) => {
|
|
530
623
|
var _a;
|
|
531
|
-
const
|
|
532
|
-
const
|
|
624
|
+
const isFunctionClass = typeof props.class === "function";
|
|
625
|
+
const isFunctionStyle = typeof props.style === "function";
|
|
626
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
627
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
628
|
+
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
533
629
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
].includes(key2) && typeof value === "function") {
|
|
538
|
-
props2[key2] = value(vnode.props[key2]);
|
|
630
|
+
var _a2;
|
|
631
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
632
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
539
633
|
}
|
|
540
634
|
return props2;
|
|
541
635
|
}, props);
|
|
542
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
636
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
637
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
638
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
639
|
+
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
function defineReactiveView(param1, param2) {
|
|
645
|
+
const instance = (0, import_vue2.ref)();
|
|
646
|
+
return (0, import_vue2.defineComponent)({
|
|
647
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
648
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
649
|
+
setup() {
|
|
650
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
651
|
+
return (component) => {
|
|
652
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
653
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
654
|
+
}, {});
|
|
655
|
+
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;
|
|
656
|
+
return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
657
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
658
|
+
} : {})), {
|
|
659
|
+
instance
|
|
660
|
+
}), slots);
|
|
548
661
|
};
|
|
549
662
|
}
|
|
550
663
|
});
|
|
664
|
+
}
|
|
665
|
+
function showComponent(component, options = {}) {
|
|
666
|
+
var _a;
|
|
667
|
+
if (options.router) {
|
|
668
|
+
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
669
|
+
}
|
|
670
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
671
|
+
const container = options.container || "app-dialogs";
|
|
672
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
673
|
+
if (!dialogs.hasAttribute("id")) {
|
|
674
|
+
dialogs.setAttribute("id", container);
|
|
675
|
+
document.body.appendChild(dialogs);
|
|
676
|
+
}
|
|
677
|
+
const dialog = document.createElement("div");
|
|
678
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
679
|
+
dialog.setAttribute("id", id);
|
|
680
|
+
dialogs.appendChild(dialog);
|
|
681
|
+
const app = (0, import_vue2.createApp)(
|
|
682
|
+
{
|
|
683
|
+
setup() {
|
|
684
|
+
return () => component;
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
__cleanup__: () => {
|
|
689
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
690
|
+
app.unmount();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
if (options.router) {
|
|
695
|
+
return app.use(options.router).mount(`#${id}`);
|
|
696
|
+
} else if (options.plugins) {
|
|
697
|
+
return options.plugins.reduce((app2, plugin) => {
|
|
698
|
+
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
699
|
+
}, app).mount(`#${id}`);
|
|
700
|
+
} else {
|
|
701
|
+
return app.mount(`#${id}`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
var getData = (component, path, alternative) => {
|
|
706
|
+
const vue = access(component);
|
|
707
|
+
const data = import_object_manager2.default.on(componentState(vue));
|
|
708
|
+
if (path) {
|
|
709
|
+
return data.get(dataPath(vue, path), alternative);
|
|
710
|
+
} else {
|
|
711
|
+
return data.get();
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
var setData = (component, data, path) => {
|
|
715
|
+
const vue = access(component);
|
|
716
|
+
const diff = {
|
|
717
|
+
before: import_object_manager2.default.on(componentState(vue)).clone(),
|
|
718
|
+
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()
|
|
719
|
+
};
|
|
720
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
721
|
+
};
|
|
722
|
+
var componentState = (component) => {
|
|
723
|
+
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
724
|
+
};
|
|
725
|
+
var dataPath = (component, path) => {
|
|
726
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
551
727
|
};
|
|
552
728
|
// Annotate the CommonJS export names for ESM import in node:
|
|
553
729
|
0 && (module.exports = {
|
|
554
730
|
MergeStyles,
|
|
555
731
|
StyleParser,
|
|
556
732
|
access,
|
|
733
|
+
dataPath,
|
|
734
|
+
defineReactiveView,
|
|
557
735
|
extendVnode,
|
|
736
|
+
getData,
|
|
558
737
|
getDate,
|
|
559
738
|
getProps,
|
|
560
739
|
getReactiveViewComponent,
|
|
561
740
|
safeRequest,
|
|
741
|
+
setData,
|
|
562
742
|
setup,
|
|
743
|
+
showComponent,
|
|
563
744
|
useSubscription
|
|
564
745
|
});
|
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)
|
|
@@ -27,6 +30,9 @@ var __objRest = (source, exclude) => {
|
|
|
27
30
|
return target;
|
|
28
31
|
};
|
|
29
32
|
|
|
33
|
+
// src/index.ts
|
|
34
|
+
import ObjectManager2 from "@razaman2/object-manager";
|
|
35
|
+
|
|
30
36
|
// src/Subscription.ts
|
|
31
37
|
var Subscription = class _Subscription {
|
|
32
38
|
constructor() {
|
|
@@ -121,11 +127,11 @@ var Subscriptions = _Subscriptions;
|
|
|
121
127
|
// src/ReactiveView.ts
|
|
122
128
|
import ObjectManager from "@razaman2/object-manager";
|
|
123
129
|
import DataManager from "@razaman2/data-manager";
|
|
124
|
-
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
|
|
130
|
+
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance, unref } from "vue";
|
|
125
131
|
|
|
126
132
|
// package.json
|
|
127
133
|
var name = "@razaman2/reactive-view";
|
|
128
|
-
var version = "0.0.34-beta.
|
|
134
|
+
var version = "0.0.34-beta.31";
|
|
129
135
|
|
|
130
136
|
// src/ReactiveView.ts
|
|
131
137
|
var setup = {
|
|
@@ -136,19 +142,16 @@ var setup = {
|
|
|
136
142
|
var ReactiveView_default = {
|
|
137
143
|
props: {
|
|
138
144
|
setup: {},
|
|
145
|
+
beta: Boolean,
|
|
139
146
|
ReactiveView: {
|
|
140
147
|
type: Boolean,
|
|
141
148
|
default: true
|
|
142
149
|
},
|
|
143
|
-
instance: {
|
|
144
|
-
default: () => ref()
|
|
145
|
-
},
|
|
150
|
+
instance: { default: ref() },
|
|
146
151
|
notifications: Object,
|
|
147
152
|
subscriptions: Object,
|
|
148
153
|
beforeSetData: Function,
|
|
149
|
-
data: {
|
|
150
|
-
default: () => ({})
|
|
151
|
-
},
|
|
154
|
+
data: { default: () => reactive({}) },
|
|
152
155
|
defaultData: {},
|
|
153
156
|
getDefaultData: {
|
|
154
157
|
type: Function,
|
|
@@ -168,10 +171,27 @@ var ReactiveView_default = {
|
|
|
168
171
|
debug: {
|
|
169
172
|
type: Boolean,
|
|
170
173
|
default: false
|
|
171
|
-
}
|
|
174
|
+
},
|
|
175
|
+
state: { default: () => reactive({}) }
|
|
172
176
|
},
|
|
173
177
|
setup(props, context) {
|
|
174
|
-
var _a, _b, _c, _d, _e, _f;
|
|
178
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
179
|
+
const diff = (before, after) => {
|
|
180
|
+
const change = after.paths().reduce((change2, path) => {
|
|
181
|
+
if (before.get(path) !== after.get(path)) {
|
|
182
|
+
change2.set(path, after.get(path));
|
|
183
|
+
}
|
|
184
|
+
return change2;
|
|
185
|
+
}, ObjectManager.on({}));
|
|
186
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
187
|
+
};
|
|
188
|
+
const dataPath2 = (path) => {
|
|
189
|
+
try {
|
|
190
|
+
return context.attrs["data:path"](path);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
return path;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
175
195
|
const template = (component2, vue2) => {
|
|
176
196
|
return createVNode(
|
|
177
197
|
"div",
|
|
@@ -183,38 +203,74 @@ var ReactiveView_default = {
|
|
|
183
203
|
};
|
|
184
204
|
const isValid = ref(false);
|
|
185
205
|
const isReady = ref(false);
|
|
186
|
-
const isFunctionData = ["Function"].includes(props.data.constructor.name);
|
|
187
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes(props.data.constructor.name);
|
|
188
|
-
const isPromiseData = ["Promise"].includes(props.data.constructor.name) || isAsyncFunctionData;
|
|
206
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
207
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
208
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
189
209
|
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
190
210
|
const vue = getCurrentInstance();
|
|
191
|
-
|
|
192
|
-
|
|
211
|
+
const emit = (after, before) => {
|
|
212
|
+
if (vue && vue.vnode.el) {
|
|
213
|
+
const event = new CustomEvent("data:emit", {
|
|
214
|
+
bubbles: true,
|
|
215
|
+
// Key: allows it to travel up
|
|
216
|
+
composed: true,
|
|
217
|
+
// Key: allows it to cross Shadow DOM boundaries
|
|
218
|
+
detail: { before, after }
|
|
219
|
+
// Payload goes here
|
|
220
|
+
});
|
|
221
|
+
vue.vnode.el.dispatchEvent(event);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
225
|
+
console.warn("[ReactiveView]: defaultData is required for promise or async function data.", props.data);
|
|
193
226
|
}
|
|
194
227
|
const defaultData = props.getDefaultData(
|
|
195
|
-
|
|
228
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(isRef(vue.vnode.props.data) ? unref(vue.vnode.props.data) : vue.vnode.props.data) ? [] : {} : {}
|
|
196
229
|
);
|
|
197
230
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
231
|
+
const normalize = (data) => {
|
|
232
|
+
if (props.debug) {
|
|
233
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
|
|
234
|
+
}
|
|
235
|
+
if (isReactive(data)) {
|
|
236
|
+
return data;
|
|
237
|
+
} else {
|
|
238
|
+
if (isRef(data) || isFunctionData || isPromiseData) {
|
|
239
|
+
return reactive(datatype);
|
|
240
|
+
} else {
|
|
241
|
+
const props2 = "data" in vue.vnode.props;
|
|
242
|
+
try {
|
|
243
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
244
|
+
return reactive(props2 ? data : datatype);
|
|
245
|
+
} else {
|
|
246
|
+
return reactive(props2 ? { "": data } : datatype);
|
|
247
|
+
}
|
|
248
|
+
} catch (e) {
|
|
249
|
+
return reactive(props2 ? { "": data } : datatype);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
198
254
|
const config = {
|
|
199
|
-
data: reactive(ObjectManager.on(
|
|
200
|
-
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype :
|
|
255
|
+
data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : reactive(ObjectManager.on(
|
|
256
|
+
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
201
257
|
).clone()),
|
|
202
258
|
defaultData: ObjectManager.on(defaultData).clone(),
|
|
203
259
|
notifications: props.notifications,
|
|
204
260
|
subscriptions: props.subscriptions,
|
|
205
|
-
|
|
206
|
-
|
|
261
|
+
name: props.modelName,
|
|
262
|
+
logging: props.logging
|
|
207
263
|
};
|
|
208
264
|
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
|
|
209
265
|
get(target, key, receiver) {
|
|
210
|
-
if (
|
|
266
|
+
if (["setData", "replaceData"].includes(key.toString())) {
|
|
211
267
|
return (...params) => {
|
|
212
268
|
var _a2;
|
|
213
269
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
214
270
|
if (typeof beforeSetData === "function") {
|
|
215
|
-
const before = target.getData();
|
|
216
|
-
const after =
|
|
217
|
-
if (beforeSetData(
|
|
271
|
+
const before = ObjectManager.on(target.getData());
|
|
272
|
+
const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
|
|
273
|
+
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
218
274
|
target[key](...params);
|
|
219
275
|
}
|
|
220
276
|
} else {
|
|
@@ -227,24 +283,25 @@ var ReactiveView_default = {
|
|
|
227
283
|
}
|
|
228
284
|
}
|
|
229
285
|
});
|
|
230
|
-
const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
286
|
+
const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
231
287
|
if (props.debug) {
|
|
232
|
-
console.
|
|
288
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
233
289
|
}
|
|
234
290
|
const watchDataProp = (dataProp) => {
|
|
235
|
-
var _a2, _b2, _c2;
|
|
291
|
+
var _a2, _b2, _c2, _d2;
|
|
236
292
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
237
293
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
238
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
294
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
295
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
296
|
+
}, 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)
|
|
239
297
|
};
|
|
240
298
|
if (context.attrs["data:log"]) {
|
|
241
|
-
console.
|
|
299
|
+
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
242
300
|
}
|
|
243
301
|
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
244
302
|
var _a3;
|
|
245
|
-
const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
|
|
246
303
|
if (typeof config2.callback === "function") {
|
|
247
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
304
|
+
model.replaceData((_a3 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a3 : after);
|
|
248
305
|
} else {
|
|
249
306
|
model.replaceData(after);
|
|
250
307
|
}
|
|
@@ -254,22 +311,53 @@ var ReactiveView_default = {
|
|
|
254
311
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
255
312
|
callback: context.attrs["onUpdate:model"],
|
|
256
313
|
options: Object.assign(__spreadValues(__spreadValues({
|
|
257
|
-
deep: (
|
|
258
|
-
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((
|
|
259
|
-
} : (
|
|
314
|
+
deep: (_e = context.attrs["model:deep"]) != null ? _e : true
|
|
315
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
|
|
316
|
+
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
260
317
|
if (context.attrs["model:log"]) {
|
|
261
|
-
console.
|
|
318
|
+
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
262
319
|
}
|
|
263
|
-
watch(() => model.getData(), (after, before) => {
|
|
264
|
-
|
|
265
|
-
config2.callback(diff, { component });
|
|
320
|
+
watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
321
|
+
config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
266
322
|
}, config2.options);
|
|
267
323
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
324
|
+
if (props.beta) {
|
|
325
|
+
const isRefData = isRef(props.data);
|
|
326
|
+
if (isRefData || isFunctionData || isPromiseData) {
|
|
327
|
+
setTimeout(async () => {
|
|
328
|
+
var _a2, _b2, _c2;
|
|
329
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
330
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
331
|
+
(_a2 = defer.value) != null ? _a2 : true
|
|
332
|
+
]) : [props.data];
|
|
333
|
+
watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
334
|
+
var _a3;
|
|
335
|
+
if (before !== void 0 || after !== void 0) {
|
|
336
|
+
const callback = context.attrs["data:callback"];
|
|
337
|
+
if (typeof callback === "function") {
|
|
338
|
+
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
339
|
+
model.replaceData((_a3 = callback(diff2, { component })) != null ? _a3 : after);
|
|
340
|
+
} else {
|
|
341
|
+
model.replaceData(after);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
346
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
347
|
+
once: context.attrs["data:once"]
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
setTimeout(async () => {
|
|
353
|
+
var _a2;
|
|
354
|
+
const [data] = await Promise.all([
|
|
355
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
356
|
+
(_a2 = defer.value) != null ? _a2 : true
|
|
357
|
+
]);
|
|
358
|
+
watchDataProp(data);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
273
361
|
setTimeout(async () => {
|
|
274
362
|
var _a2;
|
|
275
363
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -303,8 +391,10 @@ var ReactiveView_default = {
|
|
|
303
391
|
};
|
|
304
392
|
|
|
305
393
|
// src/index.ts
|
|
306
|
-
import {
|
|
394
|
+
import { h, ref as ref2, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
|
|
307
395
|
import { formatInTimeZone } from "date-fns-tz";
|
|
396
|
+
import { twMerge } from "tailwind-merge";
|
|
397
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
308
398
|
var index_default = ReactiveView_default;
|
|
309
399
|
function safeRequest(request) {
|
|
310
400
|
return new Promise(async (resolve) => {
|
|
@@ -334,7 +424,7 @@ function safeRequest(request) {
|
|
|
334
424
|
}
|
|
335
425
|
});
|
|
336
426
|
}
|
|
337
|
-
function getProps(props, param2) {
|
|
427
|
+
function getProps(props = {}, param2) {
|
|
338
428
|
var _a;
|
|
339
429
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
340
430
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -378,8 +468,9 @@ function getDate(param1, param2) {
|
|
|
378
468
|
return formatInTimeZone(datetime(), options.timezone, options.format);
|
|
379
469
|
}
|
|
380
470
|
function access(view = {}, alternative) {
|
|
471
|
+
var _a;
|
|
381
472
|
const resolve = (target) => {
|
|
382
|
-
return new Proxy(target, {
|
|
473
|
+
return new Proxy(toRaw(target), {
|
|
383
474
|
get(target2, key) {
|
|
384
475
|
const component = { tree: target2 };
|
|
385
476
|
do {
|
|
@@ -400,9 +491,8 @@ function access(view = {}, alternative) {
|
|
|
400
491
|
});
|
|
401
492
|
};
|
|
402
493
|
try {
|
|
403
|
-
const component = typeof view === "function" ? view() : view;
|
|
404
|
-
|
|
405
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
494
|
+
const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
|
|
495
|
+
return resolve("instance" in component ? component.instance : component);
|
|
406
496
|
} catch (e) {
|
|
407
497
|
return resolve(view);
|
|
408
498
|
}
|
|
@@ -485,37 +575,125 @@ var extendVnode = (component, element) => {
|
|
|
485
575
|
const vnode = getVnode();
|
|
486
576
|
return (props = {}, slots) => {
|
|
487
577
|
var _a;
|
|
488
|
-
const
|
|
489
|
-
const
|
|
578
|
+
const isFunctionClass = typeof props.class === "function";
|
|
579
|
+
const isFunctionStyle = typeof props.style === "function";
|
|
580
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
581
|
+
const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
582
|
+
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
490
583
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
].includes(key2) && typeof value === "function") {
|
|
495
|
-
props2[key2] = value(vnode.props[key2]);
|
|
584
|
+
var _a2;
|
|
585
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
586
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
496
587
|
}
|
|
497
588
|
return props2;
|
|
498
589
|
}, props);
|
|
499
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
504
|
-
return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
590
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
591
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
592
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
593
|
+
return h(finalElement, finalProps, finalSlots);
|
|
505
594
|
};
|
|
506
595
|
}
|
|
507
596
|
});
|
|
508
597
|
};
|
|
598
|
+
function defineReactiveView(param1, param2) {
|
|
599
|
+
const instance = ref2();
|
|
600
|
+
return defineComponent({
|
|
601
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
602
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
603
|
+
setup() {
|
|
604
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
605
|
+
return (component) => {
|
|
606
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
607
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
608
|
+
}, {});
|
|
609
|
+
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;
|
|
610
|
+
return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
611
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
612
|
+
} : {})), {
|
|
613
|
+
instance
|
|
614
|
+
}), slots);
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
function showComponent(component, options = {}) {
|
|
620
|
+
var _a;
|
|
621
|
+
if (options.router) {
|
|
622
|
+
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
623
|
+
}
|
|
624
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
625
|
+
const container = options.container || "app-dialogs";
|
|
626
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
627
|
+
if (!dialogs.hasAttribute("id")) {
|
|
628
|
+
dialogs.setAttribute("id", container);
|
|
629
|
+
document.body.appendChild(dialogs);
|
|
630
|
+
}
|
|
631
|
+
const dialog = document.createElement("div");
|
|
632
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
633
|
+
dialog.setAttribute("id", id);
|
|
634
|
+
dialogs.appendChild(dialog);
|
|
635
|
+
const app = createApp(
|
|
636
|
+
{
|
|
637
|
+
setup() {
|
|
638
|
+
return () => component;
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
__cleanup__: () => {
|
|
643
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
644
|
+
app.unmount();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
);
|
|
648
|
+
if (options.router) {
|
|
649
|
+
return app.use(options.router).mount(`#${id}`);
|
|
650
|
+
} else if (options.plugins) {
|
|
651
|
+
return options.plugins.reduce((app2, plugin) => {
|
|
652
|
+
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
653
|
+
}, app).mount(`#${id}`);
|
|
654
|
+
} else {
|
|
655
|
+
return app.mount(`#${id}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
var getData = (component, path, alternative) => {
|
|
660
|
+
const vue = access(component);
|
|
661
|
+
const data = ObjectManager2.on(componentState(vue));
|
|
662
|
+
if (path) {
|
|
663
|
+
return data.get(dataPath(vue, path), alternative);
|
|
664
|
+
} else {
|
|
665
|
+
return data.get();
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
var setData = (component, data, path) => {
|
|
669
|
+
const vue = access(component);
|
|
670
|
+
const diff = {
|
|
671
|
+
before: ObjectManager2.on(componentState(vue)).clone(),
|
|
672
|
+
after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
|
|
673
|
+
};
|
|
674
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
675
|
+
};
|
|
676
|
+
var componentState = (component) => {
|
|
677
|
+
return unref2("state" in component ? component.state : component.$attrs.state);
|
|
678
|
+
};
|
|
679
|
+
var dataPath = (component, path) => {
|
|
680
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
681
|
+
};
|
|
509
682
|
export {
|
|
510
683
|
MergeStyles,
|
|
511
684
|
StyleParser,
|
|
512
685
|
access,
|
|
686
|
+
dataPath,
|
|
513
687
|
index_default as default,
|
|
688
|
+
defineReactiveView,
|
|
514
689
|
extendVnode,
|
|
690
|
+
getData,
|
|
515
691
|
getDate,
|
|
516
692
|
getProps,
|
|
517
693
|
getReactiveViewComponent,
|
|
518
694
|
safeRequest,
|
|
695
|
+
setData,
|
|
519
696
|
setup,
|
|
697
|
+
showComponent,
|
|
520
698
|
useSubscription
|
|
521
699
|
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@razaman2/reactive-view",
|
|
3
|
-
"version": "0.0.34-beta.
|
|
4
|
-
"description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"prepublishOnly": "npm run build",
|
|
10
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
-
"lint": "tsc",
|
|
12
|
-
"test": "cd tests/vue-ts && npm run dev"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"vue
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"@razaman2/
|
|
26
|
-
"@razaman2/
|
|
27
|
-
"
|
|
28
|
-
"date-fns
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@razaman2/reactive-view",
|
|
3
|
+
"version": "0.0.34-beta.31",
|
|
4
|
+
"description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
+
"lint": "tsc",
|
|
12
|
+
"test": "cd tests/vue-ts && npm run dev",
|
|
13
|
+
"pr": "sh pr.sh"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"vue",
|
|
17
|
+
"vue-helper",
|
|
18
|
+
"reactive-view",
|
|
19
|
+
"vue-class-component",
|
|
20
|
+
"reactive-ui"
|
|
21
|
+
],
|
|
22
|
+
"author": "razaman2",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@razaman2/data-manager": "^3.2.12",
|
|
26
|
+
"@razaman2/event-emitter": "^2.1.1",
|
|
27
|
+
"@razaman2/object-manager": "^3.4.7",
|
|
28
|
+
"date-fns": "^4.1.0",
|
|
29
|
+
"date-fns-tz": "^3.2.0",
|
|
30
|
+
"tailwind-merge": "^3.3.1",
|
|
31
|
+
"uuid": "^13.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"vue": ">=3.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/uuid": "^11.0.0",
|
|
38
|
+
"tsup": "^8.5.0",
|
|
39
|
+
"typescript": "^5.9.3",
|
|
40
|
+
"vitest": "^4.0.5"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
]
|
|
48
|
+
}
|