@blokkli/editor 2.0.0-alpha.50 → 2.0.0-alpha.52

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blokkli/editor",
3
3
  "configKey": "blokkli",
4
- "version": "2.0.0-alpha.50",
4
+ "version": "2.0.0-alpha.52",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.15.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -18,7 +18,7 @@ import 'typescript';
18
18
  import 'oxc-walker';
19
19
 
20
20
  const name = "@blokkli/editor";
21
- const version = "2.0.0-alpha.50";
21
+ const version = "2.0.0-alpha.52";
22
22
 
23
23
  function validateOption(optionKey, option, icons) {
24
24
  const errors = [];
@@ -3990,10 +3990,6 @@ const module$1 = defineNuxtModule({
3990
3990
  featureCollector,
3991
3991
  blockCollector
3992
3992
  ];
3993
- const hasErrors = [...collectors, helper].flatMap((v) => v.validate(iconCollector)).some((v) => v);
3994
- if (!helper.isDev && !helper.isPrepare && hasErrors) {
3995
- throw new Error("Failed to build bl\xF6kkli due to validation errors.");
3996
- }
3997
3993
  const context = new ModuleContext(
3998
3994
  helper,
3999
3995
  iconCollector,
@@ -4014,6 +4010,10 @@ const module$1 = defineNuxtModule({
4014
4010
  });
4015
4011
  await Promise.all(collectors.map((v) => v.init()));
4016
4012
  await Promise.all(collectors.map((v) => v.runHooks()));
4013
+ const hasErrors = [...collectors, helper].flatMap((v) => v.validate(iconCollector)).some((v) => v);
4014
+ if (!helper.isDev && !helper.isPrepare && hasErrors) {
4015
+ throw new Error("Failed to build bl\xF6kkli due to validation errors.");
4016
+ }
4017
4017
  TEMPLATES.forEach((v) => {
4018
4018
  if (typeof v === "function") {
4019
4019
  const result = v(helper);
@@ -2,7 +2,7 @@ type __VLS_Props = {
2
2
  /**
3
3
  * The (machine) name of the field that is editable.
4
4
  */
5
- name: string;
5
+ name?: string | null;
6
6
  /**
7
7
  * The text value.
8
8
  */
@@ -20,6 +20,7 @@ type __VLS_Slots = {
20
20
  }): any;
21
21
  };
22
22
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
23
+ name: string | null;
23
24
  value: string;
24
25
  tag: string;
25
26
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -2,7 +2,7 @@
2
2
  <component
3
3
  :is="tag"
4
4
  ref="root"
5
- :data-blokkli-editable-field="isEditing ? name : void 0"
5
+ :data-blokkli-editable-field="isEditingBuild ? name : void 0"
6
6
  >
7
7
  <slot :value="renderedValue" />
8
8
  </component>
@@ -15,7 +15,8 @@ import {
15
15
  inject,
16
16
  onMounted,
17
17
  onBeforeUnmount,
18
- useTemplateRef
18
+ useTemplateRef,
19
+ watch
19
20
  } from "#imports";
20
21
  import {
21
22
  INJECT_APP,
@@ -25,62 +26,77 @@ import {
25
26
  INJECT_IS_IN_REUSABLE
26
27
  } from "#blokkli/helpers/injections";
27
28
  const props = defineProps({
28
- name: { type: String, required: true },
29
+ name: { type: [String, null], required: false, default: null },
29
30
  value: { type: String, required: false, default: "" },
30
31
  tag: { type: String, required: false, default: "div" }
31
32
  });
32
33
  defineSlots();
34
+ const isEditingBuild = import.meta.blokkliEditing;
33
35
  const root = useTemplateRef("root");
34
36
  const valueOverride = ref("");
35
- const isEditing = inject(INJECT_IS_EDITING, false);
36
- const entity = inject(INJECT_ENTITY_CONTEXT, null);
37
- const editContext = inject(INJECT_EDIT_CONTEXT, null);
38
- const app = inject(INJECT_APP, null);
39
- const isInReusable = inject(INJECT_IS_IN_REUSABLE, false);
40
- if (!entity) {
41
- throw new Error("Missing entity context.");
42
- }
43
- function getValueCallback() {
44
- return props.value;
45
- }
46
37
  const renderedValue = computed(() => valueOverride.value || props.value || "");
47
- const onEditableUpdateValue = (e) => {
48
- if (e.name === props.name && e.entityUuid === entity.uuid) {
49
- valueOverride.value = e.value;
50
- }
51
- };
52
- function onStateReloaded() {
53
- valueOverride.value = "";
54
- }
55
- onMounted(() => {
56
- if (!isEditing || !editContext || !app || isInReusable) {
57
- return;
58
- }
59
- editContext.eventBus.on("editable:update", onEditableUpdateValue);
60
- editContext.eventBus.on("state:reloaded", onStateReloaded);
61
- if (root.value instanceof HTMLElement && entity) {
38
+ if (isEditingBuild) {
39
+ let getValueCallback = function() {
40
+ return props.value;
41
+ }, onStateReloaded = function() {
42
+ valueOverride.value = "";
43
+ }, registerDirective = function(name) {
44
+ if (!name || !app || !(root.value instanceof HTMLElement) || !entity) {
45
+ return;
46
+ }
62
47
  app.directive.registerDirectiveElement(
63
48
  root.value,
64
- props.name,
49
+ name,
65
50
  entity,
66
51
  "editable",
67
52
  true,
68
53
  getValueCallback
69
54
  );
70
- }
71
- });
72
- onBeforeUnmount(() => {
73
- if (editContext) {
74
- editContext.eventBus.off("editable:update", onEditableUpdateValue);
75
- editContext.eventBus.off("state:reloaded", onStateReloaded);
76
- }
77
- if (app && root.value instanceof HTMLElement && entity) {
55
+ }, unregisterDirective = function(name) {
56
+ if (!name || !app || !(root.value instanceof HTMLElement) || !entity) {
57
+ return;
58
+ }
78
59
  app.directive.unregisterDirectiveElement(
79
60
  root.value,
80
- props.name,
61
+ name,
81
62
  entity,
82
63
  "editable"
83
64
  );
84
- }
85
- });
65
+ };
66
+ const isEditing = inject(INJECT_IS_EDITING, false);
67
+ const entity = inject(INJECT_ENTITY_CONTEXT, null);
68
+ const editContext = inject(INJECT_EDIT_CONTEXT, null);
69
+ const app = inject(INJECT_APP, null);
70
+ const isInReusable = inject(INJECT_IS_IN_REUSABLE, false);
71
+ const onEditableUpdateValue = (e) => {
72
+ if (e.name === props.name && e.entityUuid === entity?.uuid) {
73
+ valueOverride.value = e.value;
74
+ }
75
+ };
76
+ onMounted(() => {
77
+ if (!isEditing || !editContext || !app || isInReusable) {
78
+ return;
79
+ }
80
+ editContext.eventBus.on("editable:update", onEditableUpdateValue);
81
+ editContext.eventBus.on("state:reloaded", onStateReloaded);
82
+ registerDirective(props.name);
83
+ });
84
+ watch(
85
+ () => props.name,
86
+ (newName, oldName) => {
87
+ if (!isEditing || !app || !entity || isInReusable) {
88
+ return;
89
+ }
90
+ unregisterDirective(oldName);
91
+ registerDirective(newName);
92
+ }
93
+ );
94
+ onBeforeUnmount(() => {
95
+ if (editContext) {
96
+ editContext.eventBus.off("editable:update", onEditableUpdateValue);
97
+ editContext.eventBus.off("state:reloaded", onStateReloaded);
98
+ }
99
+ unregisterDirective(props.name);
100
+ });
101
+ }
86
102
  </script>
@@ -2,7 +2,7 @@ type __VLS_Props = {
2
2
  /**
3
3
  * The (machine) name of the field that is editable.
4
4
  */
5
- name: string;
5
+ name?: string | null;
6
6
  /**
7
7
  * The text value.
8
8
  */
@@ -20,6 +20,7 @@ type __VLS_Slots = {
20
20
  }): any;
21
21
  };
22
22
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
23
+ name: string | null;
23
24
  value: string;
24
25
  tag: string;
25
26
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -22,10 +22,10 @@ declare const __VLS_export: import("vue").DefineComponent<{
22
22
  parentType?: string;
23
23
  isEditing?: boolean;
24
24
  }> & Readonly<{}>, {
25
- isEditing: boolean;
26
25
  props: any;
27
26
  parentType: string;
28
27
  options: any;
29
28
  editContext: BlockEditContext;
30
29
  index: number;
30
+ isEditing: boolean;
31
31
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -22,10 +22,10 @@ declare const __VLS_export: import("vue").DefineComponent<{
22
22
  parentType?: string;
23
23
  isEditing?: boolean;
24
24
  }> & Readonly<{}>, {
25
- isEditing: boolean;
26
25
  props: any;
27
26
  parentType: string;
28
27
  options: any;
29
28
  editContext: BlockEditContext;
30
29
  index: number;
30
+ isEditing: boolean;
31
31
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blokkli/editor",
3
- "version": "2.0.0-alpha.50",
3
+ "version": "2.0.0-alpha.52",
4
4
  "description": "Interactive page building experience for Nuxt",
5
5
  "keywords": [
6
6
  "cms",