directix 1.11.0 → 2.0.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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * directix v1.11.0
3
- * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
2
+ * directix v2.0.0
3
+ * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
4
4
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
5
5
  * Released under the MIT License.
6
6
  */
@@ -58,13 +58,13 @@ var __async = (__this, __arguments, generator) => {
58
58
  });
59
59
  };
60
60
  /*!
61
- * directix v1.11.0
62
- * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
61
+ * directix v2.0.0
62
+ * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
63
63
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
64
64
  * Released under the MIT License.
65
65
  */
66
66
  var _a;
67
- import { ref, unref, onUnmounted, watch, readonly, shallowRef, computed, onMounted, reactive, watchEffect, isRef, toRaw, markRaw } from "vue";
67
+ import { markRaw, shallowReactive, ref, unref, onUnmounted, watch, readonly, shallowRef, computed, onMounted, reactive, watchEffect, isRef, toRaw } from "vue";
68
68
  function createVue2Directive(hooks) {
69
69
  const directive = {
70
70
  bind(el, binding, vnode) {
@@ -77,7 +77,7 @@ function createVue2Directive(hooks) {
77
77
  },
78
78
  inserted(el, binding, vnode) {
79
79
  if (hooks.mounted) {
80
- hooks.mounted(el, normalizeBinding$1(binding), vnode);
80
+ hooks.mounted(el, normalizeBinding$2(binding), vnode);
81
81
  }
82
82
  },
83
83
  update(el, binding, vnode, oldVnode) {
@@ -85,9 +85,9 @@ function createVue2Directive(hooks) {
85
85
  if (hooks.updated) {
86
86
  hooks.updated(
87
87
  el,
88
- normalizeBinding$1(binding),
88
+ normalizeBinding$2(binding),
89
89
  vnode,
90
- normalizeBinding$1(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
90
+ normalizeBinding$2(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
91
91
  oldVnode
92
92
  );
93
93
  }
@@ -100,7 +100,7 @@ function createVue2Directive(hooks) {
100
100
  },
101
101
  unbind(el, binding, vnode) {
102
102
  if (hooks.unmounted) {
103
- hooks.unmounted(el, normalizeBinding$1(binding), vnode);
103
+ hooks.unmounted(el, normalizeBinding$2(binding), vnode);
104
104
  }
105
105
  const state2 = el.__directix_state__;
106
106
  if (state2 == null ? void 0 : state2.cleanup) {
@@ -111,7 +111,7 @@ function createVue2Directive(hooks) {
111
111
  };
112
112
  return directive;
113
113
  }
114
- function normalizeBinding$1(binding) {
114
+ function normalizeBinding$2(binding) {
115
115
  var _a2;
116
116
  return {
117
117
  value: binding.value,
@@ -128,20 +128,20 @@ function addCleanup$1(el, fn) {
128
128
  }
129
129
  }
130
130
  function createVue3Directive(hooks) {
131
- const directive = {
131
+ return {
132
132
  created(el, binding, vnode) {
133
- const state2 = {
134
- value: binding.value,
133
+ const state2 = shallowReactive({
134
+ value: binding.value != null ? markRaw(binding.value) : binding.value,
135
135
  vnode,
136
136
  cleanup: []
137
- };
137
+ });
138
138
  el.__directix_state__ = state2;
139
139
  },
140
140
  beforeMount(_el, _binding, _vnode) {
141
141
  },
142
142
  mounted(el, binding, vnode) {
143
143
  if (hooks.mounted) {
144
- hooks.mounted(el, normalizeBindingVue3(binding), vnode);
144
+ hooks.mounted(el, normalizeBinding$1(binding), vnode);
145
145
  }
146
146
  },
147
147
  beforeUpdate(_el, _binding, _vnode, _prevVnode) {
@@ -151,14 +151,14 @@ function createVue3Directive(hooks) {
151
151
  if (hooks.updated) {
152
152
  hooks.updated(
153
153
  el,
154
- normalizeBindingVue3(binding),
154
+ normalizeBinding$1(binding),
155
155
  vnode,
156
- normalizeBindingVue3(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
156
+ normalizeBinding$1(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
157
157
  prevVnode
158
158
  );
159
159
  }
160
160
  if (state2) {
161
- state2.value = binding.value;
161
+ state2.value = binding.value != null ? markRaw(binding.value) : binding.value;
162
162
  state2.vnode = vnode;
163
163
  }
164
164
  },
@@ -166,7 +166,7 @@ function createVue3Directive(hooks) {
166
166
  },
167
167
  unmounted(el, binding, vnode) {
168
168
  if (hooks.unmounted) {
169
- hooks.unmounted(el, normalizeBindingVue3(binding), vnode);
169
+ hooks.unmounted(el, normalizeBinding$1(binding), vnode);
170
170
  }
171
171
  const state2 = el.__directix_state__;
172
172
  if (state2 == null ? void 0 : state2.cleanup) {
@@ -175,9 +175,8 @@ function createVue3Directive(hooks) {
175
175
  delete el.__directix_state__;
176
176
  }
177
177
  };
178
- return directive;
179
178
  }
180
- function normalizeBindingVue3(binding) {
179
+ function normalizeBinding$1(binding) {
181
180
  var _a2;
182
181
  return {
183
182
  value: binding.value,
@@ -21951,6 +21950,121 @@ function teleportContent(content, options) {
21951
21950
  }
21952
21951
  };
21953
21952
  }
21953
+ function isCustomElement(el) {
21954
+ return el.tagName.includes("-") || customElements.get(el.tagName.toLowerCase()) !== void 0;
21955
+ }
21956
+ function applyDirectiveToCustomElement(el, directive, value, options) {
21957
+ const binding = {
21958
+ value,
21959
+ oldValue: null,
21960
+ arg: options == null ? void 0 : options.arg,
21961
+ modifiers: (options == null ? void 0 : options.modifiers) || {},
21962
+ instance: null
21963
+ };
21964
+ const vnode = { el };
21965
+ const mountedHook = directive.mounted;
21966
+ if (mountedHook) {
21967
+ mountedHook(el, binding, vnode, null);
21968
+ }
21969
+ return () => {
21970
+ const unmountedHook = directive.unmounted;
21971
+ if (unmountedHook) {
21972
+ unmountedHook(el, binding, vnode, null);
21973
+ }
21974
+ };
21975
+ }
21976
+ function defineCustomElementDirective(options) {
21977
+ const { name, directive, defaultValue, shadow = false, shadowMode = "open" } = options;
21978
+ class DirectiveCustomElement extends HTMLElement {
21979
+ constructor() {
21980
+ super();
21981
+ __publicField(this, "cleanup");
21982
+ __publicField(this, "currentValue", defaultValue);
21983
+ if (shadow) {
21984
+ this.attachShadow({ mode: shadowMode });
21985
+ }
21986
+ }
21987
+ connectedCallback() {
21988
+ this.cleanup = applyDirectiveToCustomElement(
21989
+ this,
21990
+ directive,
21991
+ this.currentValue
21992
+ );
21993
+ }
21994
+ disconnectedCallback() {
21995
+ if (this.cleanup) {
21996
+ this.cleanup();
21997
+ this.cleanup = void 0;
21998
+ }
21999
+ }
22000
+ // Allow setting value via attribute
22001
+ static get observedAttributes() {
22002
+ return ["value"];
22003
+ }
22004
+ attributeChangedCallback(attrName, oldValue, newValue) {
22005
+ if (attrName === "value" && oldValue !== newValue) {
22006
+ this.currentValue = newValue;
22007
+ if (this.cleanup) {
22008
+ this.cleanup();
22009
+ }
22010
+ this.cleanup = applyDirectiveToCustomElement(
22011
+ this,
22012
+ directive,
22013
+ this.currentValue
22014
+ );
22015
+ }
22016
+ }
22017
+ }
22018
+ customElements.define(name, DirectiveCustomElement);
22019
+ }
22020
+ function createDirectiveElement(_name, directive, options) {
22021
+ const { defaultValue, shadow = false, shadowMode = "open" } = options || {};
22022
+ return class extends HTMLElement {
22023
+ constructor() {
22024
+ super();
22025
+ __publicField(this, "cleanup");
22026
+ __publicField(this, "currentValue", defaultValue);
22027
+ if (shadow) {
22028
+ this.attachShadow({ mode: shadowMode });
22029
+ }
22030
+ }
22031
+ connectedCallback() {
22032
+ this.cleanup = applyDirectiveToCustomElement(
22033
+ this,
22034
+ directive,
22035
+ this.currentValue
22036
+ );
22037
+ }
22038
+ disconnectedCallback() {
22039
+ if (this.cleanup) {
22040
+ this.cleanup();
22041
+ this.cleanup = void 0;
22042
+ }
22043
+ }
22044
+ static get observedAttributes() {
22045
+ return ["value"];
22046
+ }
22047
+ attributeChangedCallback(_attrName, oldValue, newValue) {
22048
+ if (oldValue !== newValue) {
22049
+ this.currentValue = newValue;
22050
+ if (this.cleanup) {
22051
+ this.cleanup();
22052
+ }
22053
+ this.cleanup = applyDirectiveToCustomElement(
22054
+ this,
22055
+ directive,
22056
+ this.currentValue
22057
+ );
22058
+ }
22059
+ }
22060
+ };
22061
+ }
22062
+ function registerDirectiveElements(elements) {
22063
+ Object.entries(elements).forEach(([elementName, elementDirective]) => {
22064
+ const elementClass = createDirectiveElement(elementName, elementDirective);
22065
+ customElements.define(elementName, elementClass);
22066
+ });
22067
+ }
21954
22068
  const zhCN = {
21955
22069
  directives: {
21956
22070
  debounce: {
@@ -24066,6 +24180,7 @@ export {
24066
24180
  addPassiveListener,
24067
24181
  announce,
24068
24182
  applyAriaAttributes,
24183
+ applyDirectiveToCustomElement,
24069
24184
  assert,
24070
24185
  assertPositive,
24071
24186
  assertRange,
@@ -24113,6 +24228,7 @@ export {
24113
24228
  createDelayedClick,
24114
24229
  createDeprecationWarning,
24115
24230
  createDirectiveBenchmark,
24231
+ createDirectiveElement,
24116
24232
  createDirectiveTemplate,
24117
24233
  createEventDirective,
24118
24234
  createI18n,
@@ -24137,6 +24253,7 @@ export {
24137
24253
  deepMerge,
24138
24254
  deferNonCriticalDirective,
24139
24255
  deferTask,
24256
+ defineCustomElementDirective,
24140
24257
  defineDirective,
24141
24258
  defineDirectiveGroup,
24142
24259
  definePlugin,
@@ -24265,6 +24382,7 @@ export {
24265
24382
  isBoolean,
24266
24383
  isBrowser,
24267
24384
  isBrowserSupported,
24385
+ isCustomElement,
24268
24386
  isDOMReady,
24269
24387
  isDevtoolsAvailable,
24270
24388
  isEmpty,
@@ -24314,6 +24432,7 @@ export {
24314
24432
  preloadModule,
24315
24433
  quickPrint,
24316
24434
  recordHistogram,
24435
+ registerDirectiveElements,
24317
24436
  registerPolyfill,
24318
24437
  removeHealthCheck,
24319
24438
  requestIdleCallback,