@lvce-editor/virtual-dom 1.0.2 → 1.1.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.
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- // src/parts/ComponentUid/ComponentUid.ts
1
+ // src/parts/UidSymbol/UidSymbol.ts
2
2
  var uidSymbol = Symbol("uid");
3
- var setComponentUid = ($Element, uid) => {
4
- $Element[uidSymbol] = uid;
5
- };
3
+
4
+ // src/parts/GetUidTarget/GetUidTarget.ts
6
5
  var getUidTarget = ($Element) => {
7
6
  while ($Element) {
8
7
  if ($Element[uidSymbol]) {
@@ -12,8 +11,16 @@ var getUidTarget = ($Element) => {
12
11
  }
13
12
  return void 0;
14
13
  };
14
+
15
+ // src/parts/ComponentUid/ComponentUid.ts
16
+ var setComponentUid = ($Element, uid) => {
17
+ $Element[uidSymbol] = uid;
18
+ };
15
19
  var getComponentUid = ($Element) => {
16
20
  const $Target = getUidTarget($Element);
21
+ if (!$Target) {
22
+ return 0;
23
+ }
17
24
  return $Target[uidSymbol];
18
25
  };
19
26
  var getComponentUidFromEvent = (event) => {
@@ -266,6 +273,18 @@ var getEventListenerOptions = (eventName) => {
266
273
  }
267
274
  };
268
275
 
276
+ // src/parts/ListenerCache/ListenerCache.ts
277
+ var cache = /* @__PURE__ */ new Map();
278
+ var has = (listener) => {
279
+ return cache.has(listener);
280
+ };
281
+ var set = (listener, value) => {
282
+ cache.set(listener, value);
283
+ };
284
+ var get = (listener) => {
285
+ return cache.get(listener);
286
+ };
287
+
269
288
  // src/parts/NameAnonymousFunction/NameAnonymousFunction.ts
270
289
  var nameAnonymousFunction = (fn, name) => {
271
290
  Object.defineProperty(fn, "name", {
@@ -274,12 +293,11 @@ var nameAnonymousFunction = (fn, name) => {
274
293
  };
275
294
 
276
295
  // src/parts/GetWrappedListener/GetWrappedListener.ts
277
- var cache = /* @__PURE__ */ new Map();
278
296
  var getWrappedListener = (listener, returnValue) => {
279
297
  if (!returnValue) {
280
298
  return listener;
281
299
  }
282
- if (!cache.has(listener)) {
300
+ if (!has(listener)) {
283
301
  const wrapped = (event) => {
284
302
  const uid = getComponentUidFromEvent(event);
285
303
  const result = listener(event);
@@ -290,9 +308,9 @@ var getWrappedListener = (listener, returnValue) => {
290
308
  ipc.send("Viewlet.executeViewletCommand", uid, ...result);
291
309
  };
292
310
  nameAnonymousFunction(wrapped, listener.name);
293
- cache.set(listener, wrapped);
311
+ set(listener, wrapped);
294
312
  }
295
- return cache.get(listener);
313
+ return get(listener);
296
314
  };
297
315
 
298
316
  // src/parts/AttachEvent/AttachEvent.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -1,3 +1,3 @@
1
- export const clearNode = ($Node) => {
1
+ export const clearNode = ($Node: HTMLElement): void => {
2
2
  $Node.textContent = ''
3
3
  }
@@ -1,21 +1,15 @@
1
- const uidSymbol = Symbol('uid')
1
+ import { getUidTarget } from '../GetUidTarget/GetUidTarget.ts'
2
+ import { uidSymbol } from '../UidSymbol/UidSymbol.ts'
2
3
 
3
4
  export const setComponentUid = ($Element, uid) => {
4
5
  $Element[uidSymbol] = uid
5
6
  }
6
7
 
7
- const getUidTarget = ($Element) => {
8
- while ($Element) {
9
- if ($Element[uidSymbol]) {
10
- return $Element
11
- }
12
- $Element = $Element.parentNode
13
- }
14
- return undefined
15
- }
16
-
17
8
  export const getComponentUid = ($Element) => {
18
9
  const $Target = getUidTarget($Element)
10
+ if (!$Target) {
11
+ return 0
12
+ }
19
13
  return $Target[uidSymbol]
20
14
  }
21
15
 
@@ -0,0 +1,11 @@
1
+ import { uidSymbol } from '../UidSymbol/UidSymbol.ts'
2
+
3
+ export const getUidTarget = ($Element) => {
4
+ while ($Element) {
5
+ if ($Element[uidSymbol]) {
6
+ return $Element
7
+ }
8
+ $Element = $Element.parentNode
9
+ }
10
+ return undefined
11
+ }
@@ -1,14 +1,13 @@
1
1
  import * as ComponentUid from '../ComponentUid/ComponentUid.ts'
2
- import * as NameAnonymousFunction from '../NameAnonymousFunction/NameAnonymousFunction.ts'
3
2
  import * as IpcState from '../IpcState/IpcState.ts'
4
-
5
- const cache = new Map()
3
+ import * as ListenerCache from '../ListenerCache/ListenerCache.ts'
4
+ import * as NameAnonymousFunction from '../NameAnonymousFunction/NameAnonymousFunction.ts'
6
5
 
7
6
  export const getWrappedListener = (listener, returnValue) => {
8
7
  if (!returnValue) {
9
8
  return listener
10
9
  }
11
- if (!cache.has(listener)) {
10
+ if (!ListenerCache.has(listener)) {
12
11
  const wrapped = (event) => {
13
12
  const uid = ComponentUid.getComponentUidFromEvent(event)
14
13
  const result = listener(event)
@@ -20,7 +19,7 @@ export const getWrappedListener = (listener, returnValue) => {
20
19
  ipc.send('Viewlet.executeViewletCommand', uid, ...result)
21
20
  }
22
21
  NameAnonymousFunction.nameAnonymousFunction(wrapped, listener.name)
23
- cache.set(listener, wrapped)
22
+ ListenerCache.set(listener, wrapped)
24
23
  }
25
- return cache.get(listener)
24
+ return ListenerCache.get(listener)
26
25
  }
@@ -0,0 +1,13 @@
1
+ const cache = new Map()
2
+
3
+ export const has = (listener) => {
4
+ return cache.has(listener)
5
+ }
6
+
7
+ export const set = (listener, value) => {
8
+ cache.set(listener, value)
9
+ }
10
+
11
+ export const get = (listener) => {
12
+ return cache.get(listener)
13
+ }
@@ -0,0 +1 @@
1
+ export const uidSymbol = Symbol('uid')
@@ -1,6 +1,11 @@
1
1
  import * as AttachEvent from '../AttachEvent/AttachEvent.ts'
2
2
 
3
- export const setProp = ($Element: HTMLElement, key: string, value: any, eventMap: any) => {
3
+ export const setProp = (
4
+ $Element: HTMLElement,
5
+ key: string,
6
+ value: any,
7
+ eventMap: any,
8
+ ) => {
4
9
  switch (key) {
5
10
  case 'maskImage':
6
11
  $Element.style.maskImage = `url('${value}')`