ddd-react 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ const c = {
2
+ ADD: "add",
3
+ REMOVE: "remove",
4
+ MOVE: "move",
5
+ NOOP: "noop"
6
+ }, o = {
7
+ TEXT: "text",
8
+ ELEMENT: "element",
9
+ FRAGMENT: "fragment",
10
+ COMPONENT: "component",
11
+ PORTAL: "portal"
12
+ };
13
+ function u(i) {
14
+ return i.filter((t) => t != null);
15
+ }
16
+ function m(i, t) {
17
+ return {
18
+ added: t.filter((e) => !i.includes(e)),
19
+ removed: i.filter((e) => !t.includes(e))
20
+ };
21
+ }
22
+ class p {
23
+ #t = [];
24
+ #e = [];
25
+ #n;
26
+ constructor(t, e) {
27
+ this.#t = [...t], this.#e = t.map((n, s) => s), this.#n = e;
28
+ }
29
+ isAddition(t, e) {
30
+ return this.findIndexFrom(t, e) === -1;
31
+ }
32
+ isNoop(t, e) {
33
+ if (t >= this.length)
34
+ return !1;
35
+ const n = this.#t[t], s = e[t];
36
+ return this.#n(n, s);
37
+ }
38
+ isRemoval(t, e) {
39
+ if (t >= this.length)
40
+ return !1;
41
+ const n = this.#t[t];
42
+ return e.findIndex(
43
+ (r) => this.#n(n, r)
44
+ ) === -1;
45
+ }
46
+ findIndexFrom(t, e) {
47
+ for (let n = e; n < this.length; n++)
48
+ if (this.#n(t, this.#t[n]))
49
+ return n;
50
+ return -1;
51
+ }
52
+ originalIndexAt(t) {
53
+ return this.#e[t];
54
+ }
55
+ noopItem(t) {
56
+ return {
57
+ op: c.NOOP,
58
+ originalIndex: this.originalIndexAt(t),
59
+ index: t,
60
+ item: this.#t[t]
61
+ };
62
+ }
63
+ removeItemsAfter(t) {
64
+ const e = [];
65
+ for (; this.length > t; )
66
+ e.push(this.removeItem(t));
67
+ return e;
68
+ }
69
+ removeItem(t) {
70
+ const e = {
71
+ op: c.REMOVE,
72
+ index: t,
73
+ item: this.#t[t]
74
+ };
75
+ return this.#t.splice(t, 1), this.#e.splice(t, 1), e;
76
+ }
77
+ addItem(t, e) {
78
+ const n = {
79
+ op: c.ADD,
80
+ index: e,
81
+ item: t
82
+ };
83
+ return this.#t.splice(e, 0, t), this.#e.splice(e, 0, -1), n;
84
+ }
85
+ moveItem(t, e) {
86
+ const n = this.findIndexFrom(t, e), s = {
87
+ op: c.MOVE,
88
+ originalIndex: this.originalIndexAt(n),
89
+ from: n,
90
+ index: e,
91
+ item: this.#t[n]
92
+ }, [r] = this.#t.splice(n, 1);
93
+ this.#t.splice(e, 0, r);
94
+ const [h] = this.#e.splice(n, 1);
95
+ return this.#e.splice(e, 0, h), s;
96
+ }
97
+ get length() {
98
+ return this.#t.length;
99
+ }
100
+ }
101
+ function d(i, t, e = (n, s) => n === s) {
102
+ const n = [], s = new p(i, e);
103
+ for (let r = 0; r < t.length; r++) {
104
+ if (s.isRemoval(r, t)) {
105
+ n.push(s.removeItem(r)), r--;
106
+ continue;
107
+ }
108
+ if (s.isNoop(r, t)) {
109
+ n.push(s.noopItem(r));
110
+ continue;
111
+ }
112
+ const h = t[r];
113
+ if (s.isAddition(h, r)) {
114
+ n.push(s.addItem(h, r));
115
+ continue;
116
+ }
117
+ n.push(s.moveItem(h, r));
118
+ }
119
+ return n.push(...s.removeItemsAfter(t.length)), n;
120
+ }
121
+ function I(i, t = {}, e = []) {
122
+ const n = typeof i == "string" ? o.ELEMENT : o.COMPONENT;
123
+ return {
124
+ tag: i,
125
+ props: t,
126
+ type: n,
127
+ children: l(u(e))
128
+ };
129
+ }
130
+ function a(i) {
131
+ return {
132
+ type: o.TEXT,
133
+ value: i,
134
+ props: {}
135
+ };
136
+ }
137
+ function g(i) {
138
+ return {
139
+ type: o.FRAGMENT,
140
+ children: l(u(i)),
141
+ props: {}
142
+ };
143
+ }
144
+ function E(i, t) {
145
+ return {
146
+ type: o.PORTAL,
147
+ children: l(u(i)),
148
+ props: {},
149
+ container: t
150
+ };
151
+ }
152
+ function l(i) {
153
+ return i.map((t) => typeof t == "string" ? a(t) : t);
154
+ }
155
+ function f(i) {
156
+ if (!i.children)
157
+ return [];
158
+ const t = [];
159
+ for (const e of i.children)
160
+ e.type === o.FRAGMENT ? t.push(...f(e)) : t.push(e);
161
+ return t;
162
+ }
163
+ export {
164
+ c as A,
165
+ o as D,
166
+ d as a,
167
+ m as b,
168
+ E as c,
169
+ I as d,
170
+ f as e,
171
+ a as f,
172
+ g as h
173
+ };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,5 @@ import { createRef } from './ref';
6
6
  import type { Ref } from './ref';
7
7
  import type { ComponentType } from './types/types';
8
8
  import { createPortal } from './portal';
9
- import { jsx } from "./jsx/jsx-runtime";
10
- import { jsxDEV } from "./jsx/jsx-dev-runtime";
11
9
  export type { ComponentType, Ref };
12
- export { Component, createContext, createRef, h, hFragment, hString, render, createPortal, jsx, jsxDEV };
10
+ export { Component, createContext, createRef, h, hFragment, hString, render, createPortal };