@razaman2/reactive-view 0.1.0-beta.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1 -1
  3. package/dist/Editor-BX8prqWt.mjs +364 -0
  4. package/dist/Editor-DKILsiST.js +1 -0
  5. package/dist/Label-B63BpiJm.mjs +49 -0
  6. package/dist/Label-ClklvtMk.js +1 -0
  7. package/dist/ReactiveView.d.mts +20 -0
  8. package/dist/ReactiveView.d.ts +20 -0
  9. package/dist/Select-CSA5Sk_b.mjs +238 -0
  10. package/dist/Select-CqG647qR.js +1 -0
  11. package/dist/Subscription.d.mts +17 -0
  12. package/dist/Subscription.d.ts +17 -0
  13. package/dist/Subscriptions.d.mts +5 -0
  14. package/dist/Subscriptions.d.ts +5 -0
  15. package/dist/Types.d.mts +28 -0
  16. package/dist/Types.d.ts +28 -0
  17. package/dist/components/Button.vue.d.mts +3 -0
  18. package/dist/components/Button.vue.d.ts +3 -0
  19. package/dist/components/ConfirmationModal.vue.d.mts +3 -0
  20. package/dist/components/ConfirmationModal.vue.d.ts +3 -0
  21. package/dist/components/CustomAlert.vue.d.mts +69 -0
  22. package/dist/components/CustomAlert.vue.d.ts +69 -0
  23. package/dist/components/CustomButton.vue.d.mts +3 -0
  24. package/dist/components/CustomButton.vue.d.ts +3 -0
  25. package/dist/components/CustomModal.vue.d.mts +3 -0
  26. package/dist/components/CustomModal.vue.d.ts +3 -0
  27. package/dist/components/CustomTable.vue.d.mts +3 -0
  28. package/dist/components/CustomTable.vue.d.ts +3 -0
  29. package/dist/components/CustomTableRow.vue.d.mts +3 -0
  30. package/dist/components/CustomTableRow.vue.d.ts +3 -0
  31. package/dist/components/Datetime.vue.d.mts +3 -0
  32. package/dist/components/Datetime.vue.d.ts +3 -0
  33. package/dist/components/DraggableList.vue.d.mts +3 -0
  34. package/dist/components/DraggableList.vue.d.ts +3 -0
  35. package/dist/components/Editor.vue.d.mts +3 -0
  36. package/dist/components/Editor.vue.d.ts +3 -0
  37. package/dist/components/Input.vue.d.mts +3 -0
  38. package/dist/components/Input.vue.d.ts +3 -0
  39. package/dist/components/ItemsList.vue.d.mts +3 -0
  40. package/dist/components/ItemsList.vue.d.ts +3 -0
  41. package/dist/components/Label.vue.d.mts +3 -0
  42. package/dist/components/Label.vue.d.ts +3 -0
  43. package/dist/components/ListPagination.vue.d.mts +3 -0
  44. package/dist/components/ListPagination.vue.d.ts +3 -0
  45. package/dist/components/Popover.vue.d.mts +3 -0
  46. package/dist/components/Popover.vue.d.ts +3 -0
  47. package/dist/components/Select.vue.d.mts +3 -0
  48. package/dist/components/Select.vue.d.ts +3 -0
  49. package/dist/components/drag.d.mts +1 -0
  50. package/dist/components/drag.d.ts +1 -0
  51. package/dist/components/index.d.mts +17 -0
  52. package/dist/components/index.d.ts +17 -0
  53. package/dist/components/masks.d.mts +22 -0
  54. package/dist/components/masks.d.ts +22 -0
  55. package/dist/components.js +1 -0
  56. package/dist/components.mjs +1660 -0
  57. package/dist/index.d.mts +42 -121
  58. package/dist/index.d.ts +42 -121
  59. package/dist/index.js +1 -963
  60. package/dist/index.mjs +2 -916
  61. package/dist/reactive-view.css +2 -0
  62. package/dist/rolldown-runtime-C-QNzSnW.mjs +11 -0
  63. package/dist/src-CB2Ym95H.js +1 -0
  64. package/dist/src-DgPt5VTg.mjs +523 -0
  65. package/package.json +126 -48
package/dist/index.mjs CHANGED
@@ -1,916 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
-
33
- // src/index.ts
34
- import ObjectManager2 from "@razaman2/object-manager";
35
-
36
- // src/Subscription.ts
37
- var Subscription = class _Subscription {
38
- constructor() {
39
- this.subscriptions = [];
40
- this.data = {};
41
- }
42
- static create() {
43
- return new _Subscription();
44
- }
45
- subscribe(name, handler, data) {
46
- if (this.isNameAvailable(name)) {
47
- this.subscriptions.push({
48
- name,
49
- handler
50
- });
51
- this.data[name] = data;
52
- }
53
- return this;
54
- }
55
- replace(name, handler, data) {
56
- this.unsubscribe(name);
57
- return this.subscribe(name, handler, data);
58
- }
59
- unsubscribe(param1) {
60
- if (!Array.isArray(param1)) {
61
- param1 = param1 ? [param1] : [];
62
- }
63
- const log = (name) => {
64
- return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
65
- };
66
- if (param1.length) {
67
- param1.forEach((name) => {
68
- const subscription = this.find(name);
69
- if (subscription) {
70
- subscription.handler();
71
- this.remove(subscription);
72
- log(name);
73
- }
74
- });
75
- } else {
76
- this.subscriptions.forEach((subscription) => {
77
- subscription.handler();
78
- log(subscription.name);
79
- });
80
- this.subscriptions = [];
81
- }
82
- return this;
83
- }
84
- size() {
85
- return this.subscriptions.length;
86
- }
87
- hasSubscription(name) {
88
- return Boolean(this.find(name));
89
- }
90
- remove(subscription) {
91
- this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
92
- }
93
- find(name) {
94
- return this.subscriptions.find((subscription) => {
95
- return subscription.name === name;
96
- });
97
- }
98
- isNameAvailable(name) {
99
- if (this.hasSubscription(name)) {
100
- throw new Error(`There is already a subscription called "${name}".`);
101
- } else {
102
- return true;
103
- }
104
- }
105
- registrations() {
106
- return this.subscriptions;
107
- }
108
- get(name) {
109
- const subscription = this.find(name);
110
- if (subscription) {
111
- return subscription;
112
- } else {
113
- throw new Error(`Subscription "${name}" doesn't exist!`);
114
- }
115
- }
116
- };
117
-
118
- // src/Subscriptions.ts
119
- var _Subscriptions = class _Subscriptions extends Subscription {
120
- static get() {
121
- return this.subscriptions;
122
- }
123
- };
124
- _Subscriptions.subscriptions = _Subscriptions.create();
125
- var Subscriptions = _Subscriptions;
126
-
127
- // src/ReactiveView.ts
128
- import ObjectManager from "@razaman2/object-manager";
129
- import DataManager from "@razaman2/data-manager";
130
- import { ref, reactive, watch, unref, isRef, isReactive, createVNode, getCurrentInstance, onBeforeUnmount } from "vue";
131
-
132
- // package.json
133
- var version = "0.1.0-beta.8";
134
- var package_default = {
135
- name: "@razaman2/reactive-view",
136
- version,
137
- 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.",
138
- main: "dist/index.js",
139
- module: "dist/index.mjs",
140
- types: "dist/index.d.ts",
141
- scripts: {
142
- prepublishOnly: "npm run build",
143
- build: "tsup src/index.ts --format cjs,esm --dts",
144
- lint: "tsc",
145
- test: "cd tests/vue-ts && npm run dev",
146
- pr: "sh pr.sh"
147
- },
148
- keywords: [
149
- "vue",
150
- "vue-helper",
151
- "reactive-view",
152
- "vue-class-component",
153
- "reactive-ui"
154
- ],
155
- author: "razaman2",
156
- license: "MIT",
157
- dependencies: {
158
- "@razaman2/data-manager": "^3.3.8",
159
- "@razaman2/event-emitter": "^2.1.1",
160
- "@razaman2/object-manager": "^3.4.7",
161
- "date-fns": "^4.1.0",
162
- "date-fns-tz": "^3.2.0",
163
- "tailwind-merge": "^3.5.0",
164
- uuid: "^13.0.0"
165
- },
166
- peerDependencies: {
167
- vue: ">=3.0.0"
168
- },
169
- devDependencies: {
170
- "@types/uuid": "^11.0.0",
171
- tsup: "^8.5.1",
172
- typescript: "^5.9.3",
173
- vitest: "^4.1.2"
174
- },
175
- publishConfig: {
176
- access: "public"
177
- },
178
- files: [
179
- "dist"
180
- ]
181
- };
182
-
183
- // src/ReactiveView.ts
184
- var setup = {
185
- type: Function,
186
- default: (parent = {}, self = {}) => self,
187
- ReactiveView: true
188
- };
189
- var ReactiveView_default = {
190
- props: {
191
- setup: {},
192
- beta: [Boolean, String],
193
- ReactiveView: {
194
- type: Boolean,
195
- default: true
196
- },
197
- instance: { default: ref() },
198
- notifications: Object,
199
- subscriptions: Object,
200
- beforeSetData: Function,
201
- data: { default: reactive({}) },
202
- defaultData: {},
203
- getDefaultData: {
204
- type: Function,
205
- default: (data) => data
206
- },
207
- model: {},
208
- defer: {},
209
- logging: {
210
- validator: (logging) => {
211
- return ["Boolean"].includes(logging.constructor.name);
212
- }
213
- },
214
- modelName: {
215
- type: String,
216
- default: "ReactiveView"
217
- },
218
- debug: {
219
- type: Boolean,
220
- default: false
221
- },
222
- state: { default: reactive({}) }
223
- },
224
- setup(props, context) {
225
- var _a, _b, _c;
226
- const subscriptions = [];
227
- onBeforeUnmount(() => subscriptions.forEach((subscription) => subscription()));
228
- const diff = (before, after) => {
229
- const changed = ref(false);
230
- const paths = Array.from(new Set(before.paths().concat(after.paths())));
231
- const changes = paths.reduce((changes2, path) => {
232
- if (before.get(path) !== after.get(path)) {
233
- changes2.set(path, after.get(path));
234
- changed.value = true;
235
- }
236
- return changes2;
237
- }, ObjectManager.on({}));
238
- return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
239
- };
240
- const dataPath2 = (path) => {
241
- try {
242
- return context.attrs["data:path"](path);
243
- } catch (e) {
244
- return path;
245
- }
246
- };
247
- const template = (component, vue2) => {
248
- return createVNode("div", context.slots.default ? context.attrs : __spreadValues({
249
- style: { color: "red", textAlign: "center" }
250
- }, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
251
- };
252
- const isValid = ref(false);
253
- const isReady = ref(false);
254
- const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
255
- const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
256
- const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
257
- const isAsyncData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
258
- const vue = getCurrentInstance();
259
- const defaultData = props.getDefaultData(
260
- "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
261
- );
262
- const datatype = Array.isArray(defaultData) ? [] : {};
263
- const beta = () => {
264
- var _a2;
265
- const emit = (after, before) => {
266
- if (vue && vue.vnode.el) {
267
- const event = new CustomEvent("data:emit", {
268
- bubbles: true,
269
- // Key: allows it to travel up
270
- composed: true,
271
- // Key: allows it to cross Shadow DOM boundaries
272
- detail: { before, after }
273
- // Payload goes here
274
- });
275
- access(component).model.setData(after);
276
- vue.vnode.el.dispatchEvent(event);
277
- }
278
- };
279
- const proxy = (data) => {
280
- return new Proxy(data, {
281
- get(target, key, receiver) {
282
- if (["setData", "replaceData"].includes(key.toString())) {
283
- return (...params) => {
284
- var _a3;
285
- const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
286
- if (typeof beforeSetData === "function") {
287
- const before = ObjectManager.on(target.getData());
288
- const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
289
- const diff2 = access(component).diff(before, after);
290
- if (beforeSetData(diff2, target)) {
291
- target[key](...params);
292
- }
293
- } else {
294
- target[key](...params);
295
- }
296
- return target;
297
- };
298
- } else {
299
- return Reflect.get(target, key, receiver);
300
- }
301
- }
302
- });
303
- };
304
- const normalize = (data) => {
305
- if (isRef(data) || isReactive(data)) {
306
- return data;
307
- } else if (isFunctionData || isAsyncData) {
308
- return ref(datatype);
309
- } else {
310
- const props2 = "data" in vue.vnode.props;
311
- try {
312
- if (["Array", "Object"].includes(data.constructor.name)) {
313
- return ref(data);
314
- } else {
315
- return ref(props2 ? { "": data } : datatype);
316
- }
317
- } catch (e) {
318
- return ref(props2 ? { "": data } : datatype);
319
- }
320
- }
321
- };
322
- const config = {
323
- data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
324
- defaultData: ObjectManager.on(defaultData).clone(),
325
- notifications: props.notifications,
326
- subscriptions: props.subscriptions,
327
- name: props.modelName,
328
- logging: props.logging
329
- };
330
- const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : DataManager.setConfig({ beforeGetData: (data) => isRef(data) ? unref(data) : data }, config);
331
- const component = ref({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
332
- if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
333
- const config2 = {
334
- callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
335
- options: {
336
- immediate: context.attrs["model:immediate"],
337
- deep: context.attrs["model:deep"],
338
- once: context.attrs["model:once"]
339
- }
340
- };
341
- const source = () => ObjectManager.on(model.getData()).clone();
342
- subscriptions.push(watch(source, (after, before) => {
343
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
344
- if (props.debug) {
345
- console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
346
- }
347
- if (diff2.changed) {
348
- config2.callback(diff2, { component });
349
- }
350
- }, config2.options));
351
- }
352
- const track = (source, options = {}) => {
353
- var _a3, _b2, _c2, _d, _e;
354
- subscriptions.push(watch(source, async (after, before) => {
355
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
356
- const callback = context.attrs["data:callback"];
357
- if (props.debug) {
358
- console.warn(`[${props.modelName}]:data`, { diff: diff2, callback, before, after, props, context, component });
359
- }
360
- if (typeof callback === "function") {
361
- callback(diff2, { component });
362
- } else {
363
- model.replaceData(after);
364
- }
365
- }, {
366
- immediate: (_b2 = (_a3 = context.attrs["data:immediate"]) != null ? _a3 : options.immediate) != null ? _b2 : true,
367
- deep: (_d = (_c2 = context.attrs["data:deep"]) != null ? _c2 : options.deep) != null ? _d : true,
368
- once: (_e = context.attrs["data:once"]) != null ? _e : options.once
369
- }));
370
- };
371
- setTimeout(async () => {
372
- var _a3;
373
- if (props.model !== false) {
374
- if (isFunctionData || isAsyncData) {
375
- if (!("defaultData" in vue.vnode.props)) {
376
- console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
377
- }
378
- const [data] = isAsyncData ? await Promise.all([
379
- isAsyncFunctionData ? props.data() : props.data,
380
- (_a3 = defer.value) != null ? _a3 : true
381
- ]) : [props.data];
382
- track(typeof data === "function" ? data : (() => data));
383
- } else {
384
- track(props.data, { immediate: false, deep: false });
385
- }
386
- }
387
- });
388
- setTimeout(async () => {
389
- var _a3;
390
- isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
391
- });
392
- component.value = [access(component)].reduce((options, parent) => {
393
- var _a3;
394
- while (parent) {
395
- if (typeof parent.setup === "function") {
396
- options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
397
- if (access(parent.$parent).ReactiveView) {
398
- break;
399
- } else {
400
- parent = access(parent.$parent);
401
- }
402
- } else {
403
- break;
404
- }
405
- }
406
- return options;
407
- }, component.value);
408
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
409
- return (vue2) => {
410
- var _a3, _b2;
411
- if (isReady.value) {
412
- return access(component).template(component, vue2);
413
- } else {
414
- return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
415
- }
416
- };
417
- };
418
- const current = () => {
419
- var _a2, _b2, _c2, _d;
420
- const emit = (after, before) => {
421
- if (vue && vue.vnode.el) {
422
- const event = new CustomEvent("data:emit", {
423
- bubbles: true,
424
- // Key: allows it to travel up
425
- composed: true,
426
- // Key: allows it to cross Shadow DOM boundaries
427
- detail: { before, after }
428
- // Payload goes here
429
- });
430
- vue.vnode.el.dispatchEvent(event);
431
- }
432
- };
433
- const normalize = (data) => {
434
- if (props.debug) {
435
- console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
436
- }
437
- if (isReactive(data)) {
438
- return data;
439
- } else {
440
- if (isRef(data) || isFunctionData || isAsyncData) {
441
- return reactive(datatype);
442
- } else {
443
- const props2 = "data" in vue.vnode.props;
444
- try {
445
- if (["Array", "Object"].includes(data.constructor.name)) {
446
- return reactive(props2 ? data : datatype);
447
- } else {
448
- return reactive(props2 ? { "": data } : datatype);
449
- }
450
- } catch (e) {
451
- return reactive(props2 ? { "": data } : datatype);
452
- }
453
- }
454
- }
455
- };
456
- const config = {
457
- data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
458
- isAsyncData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
459
- ).clone()),
460
- defaultData: ObjectManager.on(defaultData).clone(),
461
- notifications: props.notifications,
462
- subscriptions: props.subscriptions,
463
- name: props.modelName,
464
- logging: props.logging
465
- };
466
- const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
467
- get(target, key, receiver) {
468
- if (["setData", "replaceData"].includes(key.toString())) {
469
- return (...params) => {
470
- var _a3;
471
- const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
472
- if (typeof beforeSetData === "function") {
473
- const before = ObjectManager.on(target.getData());
474
- const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
475
- if (beforeSetData(access(component).diff(before, after), target)) {
476
- target[key](...params);
477
- }
478
- } else {
479
- target[key](...params);
480
- }
481
- return target;
482
- };
483
- } else {
484
- return Reflect.get(target, key, receiver);
485
- }
486
- }
487
- });
488
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
489
- if (props.debug) {
490
- console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
491
- }
492
- const watchDataProp = (dataProp) => {
493
- var _a3, _b3, _c3, _d2;
494
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
495
- callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
496
- options: Object.assign(__spreadValues(__spreadValues({
497
- deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
498
- }, 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)
499
- };
500
- if (context.attrs["data:log"]) {
501
- console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
502
- }
503
- subscriptions.push(watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
504
- var _a4;
505
- if (typeof config2.callback === "function") {
506
- model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
507
- } else {
508
- model.replaceData(after);
509
- }
510
- }, config2.options));
511
- };
512
- if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
513
- const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
514
- callback: context.attrs["onUpdate:model"],
515
- options: Object.assign(__spreadValues(__spreadValues({
516
- deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
517
- }, 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)
518
- } : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
519
- if (context.attrs["model:log"]) {
520
- console.warn(`[ReactiveView]:model`, { config: config2 });
521
- }
522
- subscriptions.push(watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
523
- config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
524
- }, config2.options));
525
- }
526
- if (props.beta) {
527
- const isRefData = isRef(props.data);
528
- if (isRefData || isFunctionData || isAsyncData) {
529
- setTimeout(async () => {
530
- var _a3, _b3, _c3;
531
- const [data] = isAsyncData ? await Promise.all([
532
- isAsyncFunctionData ? props.data() : props.data,
533
- (_a3 = defer.value) != null ? _a3 : true
534
- ]) : [props.data];
535
- subscriptions.push(watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
536
- var _a4;
537
- if (before !== void 0 || after !== void 0) {
538
- const callback = context.attrs["data:callback"];
539
- if (typeof callback === "function") {
540
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
541
- model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
542
- } else {
543
- model.replaceData(after);
544
- }
545
- }
546
- }, {
547
- immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
548
- deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
549
- once: context.attrs["data:once"]
550
- }));
551
- });
552
- }
553
- } else {
554
- setTimeout(async () => {
555
- var _a3;
556
- const [data] = await Promise.all([
557
- isAsyncFunctionData ? props.data() : props.data,
558
- (_a3 = defer.value) != null ? _a3 : true
559
- ]);
560
- watchDataProp(data);
561
- });
562
- }
563
- setTimeout(async () => {
564
- var _a3;
565
- isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
566
- });
567
- component.value = [access(component)].reduce((options, parent) => {
568
- var _a3;
569
- while (parent) {
570
- if (typeof parent.setup === "function") {
571
- options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
572
- if (access(parent.$parent).ReactiveView) {
573
- break;
574
- } else {
575
- parent = access(parent.$parent);
576
- }
577
- } else {
578
- break;
579
- }
580
- }
581
- return options;
582
- }, component.value);
583
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
584
- return (vue2) => {
585
- var _a3, _b3;
586
- if (isReady.value) {
587
- return access(component).template(component, vue2);
588
- } else {
589
- return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
590
- }
591
- };
592
- };
593
- return props.beta === "next" ? beta() : current();
594
- }
595
- };
596
-
597
- // src/index.ts
598
- import { h, ref as ref2, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
599
- import { formatInTimeZone } from "date-fns-tz";
600
- import { twMerge } from "tailwind-merge";
601
- console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
602
- var index_default = ReactiveView_default;
603
- function safeRequest(request) {
604
- return new Promise(async (resolve) => {
605
- var _a, _b, _c, _d;
606
- const { message } = (_a = request.loading) != null ? _a : {};
607
- if (request.loading) {
608
- request.loading.status = true;
609
- if (request.message) {
610
- request.loading.message = request.message;
611
- }
612
- }
613
- try {
614
- resolve(await request.try());
615
- } catch (e) {
616
- if ((_b = request.alternative) != null ? _b : true) {
617
- resolve(request.catch ? await request.catch(e) : console.log(e));
618
- }
619
- } finally {
620
- await ((_c = request.finally) == null ? void 0 : _c.call(request));
621
- if (request.loading) {
622
- request.loading.status = false;
623
- }
624
- if (request.loading && message) {
625
- request.loading.message = message;
626
- }
627
- await ((_d = request.complete) == null ? void 0 : _d.call(request));
628
- }
629
- });
630
- }
631
- function getProps(props = {}, param2) {
632
- var _a;
633
- const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
634
- const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
635
- const include = (_a = param2.include) != null ? _a : {};
636
- return Object.entries(include).reduce((props2, [key, val]) => {
637
- props2[key] = val;
638
- return props2;
639
- }, Object.entries(props).reduce((props2, [key, val]) => {
640
- if (!RegExp(`(^|\\|)${key}($|\\|)`, "i").test(exclusions)) {
641
- props2[key] = val;
642
- }
643
- return props2;
644
- }, {}));
645
- }
646
- function getReactiveViewComponent(component, options = {}) {
647
- const model = (component2) => {
648
- try {
649
- return (component2.type || component2).props.hasOwnProperty("model");
650
- } catch (e) {
651
- return false;
652
- }
653
- };
654
- const props = getProps(options, "setup");
655
- const slots = typeof component === "function" ? component : () => {
656
- return (component.type || component).setup ? createVNode2(component, component.setup ? {} : props) : component;
657
- };
658
- return model(component) ? createVNode2(component, props) : createVNode2(ReactiveView_default, props, slots);
659
- }
660
- function getDate(param1, param2) {
661
- var _a, _b;
662
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
663
- const format = "MM/dd/yyyy h:mm a";
664
- const options = typeof param2 === "string" ? { format: param2, timezone } : { format: (_a = param2 == null ? void 0 : param2.format) != null ? _a : format, timezone: (_b = param2 == null ? void 0 : param2.timezone) != null ? _b : timezone };
665
- const datetime = () => {
666
- try {
667
- return param1 instanceof Date ? param1 : param1.toDate();
668
- } catch (e) {
669
- return /* @__PURE__ */ new Date();
670
- }
671
- };
672
- return formatInTimeZone(datetime(), options.timezone, options.format);
673
- }
674
- function access(view = {}, alternative) {
675
- var _a;
676
- const resolve = (target) => {
677
- return new Proxy(toRaw(target), {
678
- get(target2, key) {
679
- const component = { tree: target2 };
680
- do {
681
- if (key in component.tree) {
682
- return component.tree[key];
683
- } else if ("self" in component.tree && key in component.tree.self) {
684
- return component.tree.self[key];
685
- } else {
686
- component.tree = "parent" in component.tree && component.tree.parent;
687
- }
688
- } while (component.tree);
689
- try {
690
- return new alternative();
691
- } catch (e) {
692
- return alternative;
693
- }
694
- }
695
- });
696
- };
697
- try {
698
- const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
699
- return resolve("instance" in component ? component.instance : component);
700
- } catch (e) {
701
- return resolve(view);
702
- }
703
- }
704
- function useSubscription() {
705
- const subscriptions = [];
706
- const subscription = Subscriptions.get();
707
- return {
708
- addSubscription(name, handler = () => false, data) {
709
- subscription.subscribe(name, handler, data);
710
- subscriptions.push(() => subscription.unsubscribe(name));
711
- },
712
- replaceSubscription(name, handler = () => false, data) {
713
- subscription.replace(name, handler, data);
714
- subscriptions.push(() => subscription.unsubscribe(name));
715
- },
716
- removeSubscriptions() {
717
- subscriptions.forEach((subscription2) => safeRequest({
718
- try: () => subscription2()
719
- }));
720
- },
721
- removeSubscription(name) {
722
- subscription.unsubscribe(name);
723
- },
724
- hasSubscription(name) {
725
- return subscription.hasSubscription(name);
726
- },
727
- subscriptions,
728
- subscription
729
- };
730
- }
731
- var Prop = ({ default: value, type, validator, required } = {}) => {
732
- const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
733
- const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
734
- return __spreadProps(__spreadValues({}, value ? { default: ref2(value) } : {}), {
735
- required,
736
- validator: (value2) => {
737
- return validator ? validator(unref2(value2)) : Array.from(new Set(types2.map((type2) => {
738
- return typeof type2 === "function" ? type2().constructor.name : type2;
739
- }))).includes(unref2(value2).constructor.name);
740
- }
741
- });
742
- };
743
- function StyleParser(styles = {}) {
744
- const transform = (style, status = true) => {
745
- const remove = style.split(/(-{[^}]+})/);
746
- return remove.reduce((object, style2) => {
747
- var _a;
748
- const remove2 = /-{(.+?)}/.exec(style2);
749
- (remove2 ? (_a = remove2[1]) != null ? _a : style2 : style2).split(/\s+/).forEach((item) => {
750
- if (item) {
751
- Object.assign(object, { [item]: remove2 ? false : status });
752
- }
753
- });
754
- return object;
755
- }, {});
756
- };
757
- return Array.isArray(styles) ? styles.reduce((styles2, style) => Object.assign(transform(style), styles2), {}) : typeof styles === "string" ? transform(styles) : Object.entries(styles).reduce((acc, [styles2, value]) => {
758
- return __spreadValues(__spreadValues({}, acc), transform(styles2, value));
759
- }, {});
760
- }
761
- function MergeStyles(...params) {
762
- return new Proxy(params.reduce((styles, style, index, items) => {
763
- var _a;
764
- const item = (_a = items[items.length - index - 1]) != null ? _a : {};
765
- return __spreadValues(__spreadValues({}, StyleParser(typeof item === "function" ? item(items.slice(0, index - 1)) : item)), styles);
766
- }, {}), {
767
- get: (target, key, receiver) => {
768
- const styles = Object.entries(target).reduce((styles2, [key2, val]) => {
769
- return val ? styles2.concat(key2) : styles2;
770
- }, []);
771
- if (key === "string") {
772
- return styles.join(" ");
773
- } else if (key === "array") {
774
- return styles;
775
- } else {
776
- return Reflect.get(target, key, receiver);
777
- }
778
- }
779
- });
780
- }
781
- var extendVnode = (component, element) => {
782
- return new Proxy(access(component), {
783
- get: (target, key) => {
784
- const getVnode = () => {
785
- try {
786
- return target[key]();
787
- } catch (e) {
788
- throw new Error(`${key} does not exist as vnode on component.`);
789
- }
790
- };
791
- const vnode = getVnode();
792
- return (props = {}, slots) => {
793
- var _a;
794
- const isFunctionClass = typeof props.class === "function";
795
- const isFunctionStyle = typeof props.style === "function";
796
- const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
797
- const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
798
- const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
799
- const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
800
- var _a2;
801
- if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
802
- props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
803
- }
804
- return props2;
805
- }, props);
806
- const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
807
- const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
808
- const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
809
- return h(finalElement, finalProps, finalSlots);
810
- };
811
- }
812
- });
813
- };
814
- function defineReactiveView(param1, param2) {
815
- const instance = ref2();
816
- return defineComponent({
817
- name: param1 == null ? void 0 : param1.modelName,
818
- props: __spreadValues({ setup }, param1 ? param1.props : {}),
819
- setup() {
820
- const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
821
- return (component) => {
822
- const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
823
- return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
824
- }, {});
825
- 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;
826
- return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
827
- setup: (self, parent) => setup2(self, parent, component)
828
- } : {})), {
829
- instance
830
- }), slots);
831
- };
832
- }
833
- });
834
- }
835
- function showComponent(component, options = {}) {
836
- var _a;
837
- if (options.router) {
838
- console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
839
- }
840
- if (!options.key || !document.getElementById(options.key)) {
841
- const container = options.container || "app-dialogs";
842
- const dialogs = document.getElementById(container) || document.createElement("div");
843
- if (!dialogs.hasAttribute("id")) {
844
- dialogs.setAttribute("id", container);
845
- document.body.appendChild(dialogs);
846
- }
847
- const dialog = document.createElement("div");
848
- const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
849
- dialog.setAttribute("id", id);
850
- dialogs.appendChild(dialog);
851
- const app = createApp(
852
- {
853
- setup() {
854
- return () => component;
855
- }
856
- },
857
- {
858
- __cleanup__: () => {
859
- document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
860
- app.unmount();
861
- }
862
- }
863
- );
864
- if (options.router) {
865
- return app.use(options.router).mount(`#${id}`);
866
- } else if (options.plugins) {
867
- return options.plugins.reduce((app2, plugin) => {
868
- return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
869
- }, app).mount(`#${id}`);
870
- } else {
871
- return app.mount(`#${id}`);
872
- }
873
- }
874
- }
875
- var getData = (component, path, alternative) => {
876
- const vue = access(component);
877
- const data = ObjectManager2.on(componentState(vue));
878
- if (path) {
879
- return data.get(dataPath(vue, path), alternative);
880
- } else {
881
- return data.get();
882
- }
883
- };
884
- var setData = (component, data, path) => {
885
- const vue = access(component);
886
- const diff = {
887
- before: ObjectManager2.on(componentState(vue)).clone(),
888
- after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
889
- };
890
- return "state" in vue ? diff : vue.$emit("update:state", diff);
891
- };
892
- var componentState = (component) => {
893
- return unref2("state" in component ? component.state : component.$attrs.state);
894
- };
895
- var dataPath = (component, path) => {
896
- return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
897
- };
898
- export {
899
- MergeStyles,
900
- Prop,
901
- StyleParser,
902
- access,
903
- dataPath,
904
- index_default as default,
905
- defineReactiveView,
906
- extendVnode,
907
- getData,
908
- getDate,
909
- getProps,
910
- getReactiveViewComponent,
911
- safeRequest,
912
- setData,
913
- setup,
914
- showComponent,
915
- useSubscription
916
- };
1
+ import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _, y as v } from "./src-DgPt5VTg.mjs";
2
+ export { h as MergeStyles, u as Prop, p as StyleParser, s as access, t as copy, d as dataPath, a as default, m as defineReactiveView, n as extendVnode, c as getData, g as getDate, r as getProps, i as getReactiveViewComponent, f as safeRequest, l as setData, v as setup, o as showComponent, e as throwError, _ as useSubscription };