@kubik-cms/wysiwyg 0.1.22 → 0.1.25

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.
@@ -5,6 +5,13 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { Controller } from "@hotwired/stimulus";
8
+ import Header from "@editorjs/header";
9
+ import NestedList from "@editorjs/nested-list";
10
+ import Underline from "@editorjs/underline";
11
+ import Embed from "@editorjs/embed";
12
+ import Paragraph from "@editorjs/paragraph";
13
+ import Quote from "@editorjs/quote";
14
+ import Hyperlink from "editorjs-hyperlink";
8
15
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
9
16
  function getAugmentedNamespace(n) {
10
17
  if (n.__esModule)
@@ -25,18 +32,18 @@ var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && common
25
32
  var _freeGlobal = freeGlobal$1;
26
33
  var freeGlobal = _freeGlobal;
27
34
  var freeSelf = typeof self == "object" && self && self.Object === Object && self;
28
- var root$9 = freeGlobal || freeSelf || Function("return this")();
29
- var _root = root$9;
30
- var root$8 = _root;
31
- var Symbol$5 = root$8.Symbol;
32
- var _Symbol = Symbol$5;
33
- var Symbol$4 = _Symbol;
34
- var objectProto$6 = Object.prototype;
35
- var hasOwnProperty$6 = objectProto$6.hasOwnProperty;
36
- var nativeObjectToString$1 = objectProto$6.toString;
37
- var symToStringTag$1 = Symbol$4 ? Symbol$4.toStringTag : void 0;
35
+ var root$4 = freeGlobal || freeSelf || Function("return this")();
36
+ var _root = root$4;
37
+ var root$3 = _root;
38
+ var Symbol$4 = root$3.Symbol;
39
+ var _Symbol = Symbol$4;
40
+ var Symbol$3 = _Symbol;
41
+ var objectProto$5 = Object.prototype;
42
+ var hasOwnProperty$5 = objectProto$5.hasOwnProperty;
43
+ var nativeObjectToString$1 = objectProto$5.toString;
44
+ var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : void 0;
38
45
  function getRawTag$1(value) {
39
- var isOwn = hasOwnProperty$6.call(value, symToStringTag$1), tag = value[symToStringTag$1];
46
+ var isOwn = hasOwnProperty$5.call(value, symToStringTag$1), tag = value[symToStringTag$1];
40
47
  try {
41
48
  value[symToStringTag$1] = void 0;
42
49
  var unmasked = true;
@@ -53,39 +60,39 @@ function getRawTag$1(value) {
53
60
  return result2;
54
61
  }
55
62
  var _getRawTag = getRawTag$1;
56
- var objectProto$5 = Object.prototype;
57
- var nativeObjectToString = objectProto$5.toString;
63
+ var objectProto$4 = Object.prototype;
64
+ var nativeObjectToString = objectProto$4.toString;
58
65
  function objectToString$1(value) {
59
66
  return nativeObjectToString.call(value);
60
67
  }
61
68
  var _objectToString = objectToString$1;
62
- var Symbol$3 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
69
+ var Symbol$2 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
63
70
  var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
64
- var symToStringTag = Symbol$3 ? Symbol$3.toStringTag : void 0;
65
- function baseGetTag$4(value) {
71
+ var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
72
+ function baseGetTag$2(value) {
66
73
  if (value == null) {
67
74
  return value === void 0 ? undefinedTag : nullTag;
68
75
  }
69
76
  return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
70
77
  }
71
- var _baseGetTag = baseGetTag$4;
78
+ var _baseGetTag = baseGetTag$2;
72
79
  function isObject$6(value) {
73
80
  var type = typeof value;
74
81
  return value != null && (type == "object" || type == "function");
75
82
  }
76
83
  var isObject_1 = isObject$6;
77
- var baseGetTag$3 = _baseGetTag, isObject$5 = isObject_1;
84
+ var baseGetTag$1 = _baseGetTag, isObject$5 = isObject_1;
78
85
  var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
79
86
  function isFunction$1(value) {
80
87
  if (!isObject$5(value)) {
81
88
  return false;
82
89
  }
83
- var tag = baseGetTag$3(value);
90
+ var tag = baseGetTag$1(value);
84
91
  return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
85
92
  }
86
93
  var isFunction_1 = isFunction$1;
87
- var root$7 = _root;
88
- var coreJsData$1 = root$7["__core-js_shared__"];
94
+ var root$2 = _root;
95
+ var coreJsData$1 = root$2["__core-js_shared__"];
89
96
  var _coreJsData = coreJsData$1;
90
97
  var coreJsData = _coreJsData;
91
98
  var maskSrcKey = function() {
@@ -98,7 +105,7 @@ function isMasked$1(func) {
98
105
  var _isMasked = isMasked$1;
99
106
  var funcProto$1 = Function.prototype;
100
107
  var funcToString$1 = funcProto$1.toString;
101
- function toSource$2(func) {
108
+ function toSource$1(func) {
102
109
  if (func != null) {
103
110
  try {
104
111
  return funcToString$1.call(func);
@@ -111,22 +118,22 @@ function toSource$2(func) {
111
118
  }
112
119
  return "";
113
120
  }
114
- var _toSource = toSource$2;
115
- var isFunction = isFunction_1, isMasked = _isMasked, isObject$4 = isObject_1, toSource$1 = _toSource;
121
+ var _toSource = toSource$1;
122
+ var isFunction = isFunction_1, isMasked = _isMasked, isObject$4 = isObject_1, toSource = _toSource;
116
123
  var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
117
124
  var reIsHostCtor = /^\[object .+?Constructor\]$/;
118
- var funcProto = Function.prototype, objectProto$4 = Object.prototype;
125
+ var funcProto = Function.prototype, objectProto$3 = Object.prototype;
119
126
  var funcToString = funcProto.toString;
120
- var hasOwnProperty$5 = objectProto$4.hasOwnProperty;
127
+ var hasOwnProperty$4 = objectProto$3.hasOwnProperty;
121
128
  var reIsNative = RegExp(
122
- "^" + funcToString.call(hasOwnProperty$5).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
129
+ "^" + funcToString.call(hasOwnProperty$4).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
123
130
  );
124
131
  function baseIsNative$1(value) {
125
132
  if (!isObject$4(value) || isMasked(value)) {
126
133
  return false;
127
134
  }
128
135
  var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
129
- return pattern.test(toSource$1(value));
136
+ return pattern.test(toSource(value));
130
137
  }
131
138
  var _baseIsNative = baseIsNative$1;
132
139
  function getValue$1(object, key) {
@@ -134,15 +141,15 @@ function getValue$1(object, key) {
134
141
  }
135
142
  var _getValue = getValue$1;
136
143
  var baseIsNative = _baseIsNative, getValue = _getValue;
137
- function getNative$7(object, key) {
144
+ function getNative$3(object, key) {
138
145
  var value = getValue(object, key);
139
146
  return baseIsNative(value) ? value : void 0;
140
147
  }
141
- var _getNative = getNative$7;
142
- var getNative$6 = _getNative;
148
+ var _getNative = getNative$3;
149
+ var getNative$2 = _getNative;
143
150
  var defineProperty$1 = function() {
144
151
  try {
145
- var func = getNative$6(Object, "defineProperty");
152
+ var func = getNative$2(Object, "defineProperty");
146
153
  func({}, "", {});
147
154
  return func;
148
155
  } catch (e) {
@@ -168,25 +175,25 @@ function eq$2(value, other) {
168
175
  }
169
176
  var eq_1 = eq$2;
170
177
  var baseAssignValue = _baseAssignValue, eq$1 = eq_1;
171
- var objectProto$3 = Object.prototype;
172
- var hasOwnProperty$4 = objectProto$3.hasOwnProperty;
178
+ var objectProto$2 = Object.prototype;
179
+ var hasOwnProperty$3 = objectProto$2.hasOwnProperty;
173
180
  function assignValue$1(object, key, value) {
174
181
  var objValue = object[key];
175
- if (!(hasOwnProperty$4.call(object, key) && eq$1(objValue, value)) || value === void 0 && !(key in object)) {
182
+ if (!(hasOwnProperty$3.call(object, key) && eq$1(objValue, value)) || value === void 0 && !(key in object)) {
176
183
  baseAssignValue(object, key, value);
177
184
  }
178
185
  }
179
186
  var _assignValue = assignValue$1;
180
187
  var isArray$4 = Array.isArray;
181
188
  var isArray_1 = isArray$4;
182
- function isObjectLike$3(value) {
189
+ function isObjectLike$1(value) {
183
190
  return value != null && typeof value == "object";
184
191
  }
185
- var isObjectLike_1 = isObjectLike$3;
186
- var baseGetTag$2 = _baseGetTag, isObjectLike$2 = isObjectLike_1;
192
+ var isObjectLike_1 = isObjectLike$1;
193
+ var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1;
187
194
  var symbolTag = "[object Symbol]";
188
195
  function isSymbol$3(value) {
189
- return typeof value == "symbol" || isObjectLike$2(value) && baseGetTag$2(value) == symbolTag;
196
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
190
197
  }
191
198
  var isSymbol_1 = isSymbol$3;
192
199
  var isArray$3 = isArray_1, isSymbol$2 = isSymbol_1;
@@ -202,8 +209,8 @@ function isKey$1(value, object) {
202
209
  return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
203
210
  }
204
211
  var _isKey = isKey$1;
205
- var getNative$5 = _getNative;
206
- var nativeCreate$4 = getNative$5(Object, "create");
212
+ var getNative$1 = _getNative;
213
+ var nativeCreate$4 = getNative$1(Object, "create");
207
214
  var _nativeCreate = nativeCreate$4;
208
215
  var nativeCreate$3 = _nativeCreate;
209
216
  function hashClear$1() {
@@ -219,23 +226,23 @@ function hashDelete$1(key) {
219
226
  var _hashDelete = hashDelete$1;
220
227
  var nativeCreate$2 = _nativeCreate;
221
228
  var HASH_UNDEFINED$1 = "__lodash_hash_undefined__";
222
- var objectProto$2 = Object.prototype;
223
- var hasOwnProperty$3 = objectProto$2.hasOwnProperty;
229
+ var objectProto$1 = Object.prototype;
230
+ var hasOwnProperty$2 = objectProto$1.hasOwnProperty;
224
231
  function hashGet$1(key) {
225
232
  var data = this.__data__;
226
233
  if (nativeCreate$2) {
227
234
  var result2 = data[key];
228
235
  return result2 === HASH_UNDEFINED$1 ? void 0 : result2;
229
236
  }
230
- return hasOwnProperty$3.call(data, key) ? data[key] : void 0;
237
+ return hasOwnProperty$2.call(data, key) ? data[key] : void 0;
231
238
  }
232
239
  var _hashGet = hashGet$1;
233
240
  var nativeCreate$1 = _nativeCreate;
234
- var objectProto$1 = Object.prototype;
235
- var hasOwnProperty$2 = objectProto$1.hasOwnProperty;
241
+ var objectProto = Object.prototype;
242
+ var hasOwnProperty$1 = objectProto.hasOwnProperty;
236
243
  function hashHas$1(key) {
237
244
  var data = this.__data__;
238
- return nativeCreate$1 ? data[key] !== void 0 : hasOwnProperty$2.call(data, key);
245
+ return nativeCreate$1 ? data[key] !== void 0 : hasOwnProperty$1.call(data, key);
239
246
  }
240
247
  var _hashHas = hashHas$1;
241
248
  var nativeCreate = _nativeCreate;
@@ -334,15 +341,15 @@ ListCache$1.prototype.get = listCacheGet;
334
341
  ListCache$1.prototype.has = listCacheHas;
335
342
  ListCache$1.prototype.set = listCacheSet;
336
343
  var _ListCache = ListCache$1;
337
- var getNative$4 = _getNative, root$6 = _root;
338
- var Map$3 = getNative$4(root$6, "Map");
339
- var _Map = Map$3;
340
- var Hash = _Hash, ListCache = _ListCache, Map$2 = _Map;
344
+ var getNative = _getNative, root$1 = _root;
345
+ var Map$2 = getNative(root$1, "Map");
346
+ var _Map = Map$2;
347
+ var Hash = _Hash, ListCache = _ListCache, Map$1 = _Map;
341
348
  function mapCacheClear$1() {
342
349
  this.size = 0;
343
350
  this.__data__ = {
344
351
  "hash": new Hash(),
345
- "map": new (Map$2 || ListCache)(),
352
+ "map": new (Map$1 || ListCache)(),
346
353
  "string": new Hash()
347
354
  };
348
355
  }
@@ -453,9 +460,9 @@ function arrayMap$1(array, iteratee) {
453
460
  return result2;
454
461
  }
455
462
  var _arrayMap = arrayMap$1;
456
- var Symbol$2 = _Symbol, arrayMap = _arrayMap, isArray$2 = isArray_1, isSymbol$1 = isSymbol_1;
463
+ var Symbol$1 = _Symbol, arrayMap = _arrayMap, isArray$2 = isArray_1, isSymbol$1 = isSymbol_1;
457
464
  var INFINITY$1 = 1 / 0;
458
- var symbolProto$1 = Symbol$2 ? Symbol$2.prototype : void 0, symbolToString = symbolProto$1 ? symbolProto$1.toString : void 0;
465
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
459
466
  function baseToString$1(value) {
460
467
  if (typeof value == "string") {
461
468
  return value;
@@ -547,99 +554,6 @@ function get(object, path, defaultValue) {
547
554
  return result2 === void 0 ? defaultValue : result2;
548
555
  }
549
556
  var get_1 = get;
550
- var root$5 = _root;
551
- root$5.Uint8Array;
552
- var Symbol$1 = _Symbol;
553
- var symbolProto = Symbol$1 ? Symbol$1.prototype : void 0;
554
- symbolProto ? symbolProto.valueOf : void 0;
555
- var baseGetTag$1 = _baseGetTag, isObjectLike$1 = isObjectLike_1;
556
- var argsTag = "[object Arguments]";
557
- function baseIsArguments$1(value) {
558
- return isObjectLike$1(value) && baseGetTag$1(value) == argsTag;
559
- }
560
- var _baseIsArguments = baseIsArguments$1;
561
- var baseIsArguments = _baseIsArguments, isObjectLike = isObjectLike_1;
562
- var objectProto = Object.prototype;
563
- var hasOwnProperty$1 = objectProto.hasOwnProperty;
564
- var propertyIsEnumerable = objectProto.propertyIsEnumerable;
565
- baseIsArguments(function() {
566
- return arguments;
567
- }()) ? baseIsArguments : function(value) {
568
- return isObjectLike(value) && hasOwnProperty$1.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
569
- };
570
- var isBuffer = { exports: {} };
571
- function stubFalse() {
572
- return false;
573
- }
574
- var stubFalse_1 = stubFalse;
575
- (function(module, exports) {
576
- var root2 = _root, stubFalse2 = stubFalse_1;
577
- var freeExports = exports && !exports.nodeType && exports;
578
- var freeModule = freeExports && true && module && !module.nodeType && module;
579
- var moduleExports = freeModule && freeModule.exports === freeExports;
580
- var Buffer2 = moduleExports ? root2.Buffer : void 0;
581
- var nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0;
582
- var isBuffer2 = nativeIsBuffer || stubFalse2;
583
- module.exports = isBuffer2;
584
- })(isBuffer, isBuffer.exports);
585
- var _nodeUtil = { exports: {} };
586
- (function(module, exports) {
587
- var freeGlobal2 = _freeGlobal;
588
- var freeExports = exports && !exports.nodeType && exports;
589
- var freeModule = freeExports && true && module && !module.nodeType && module;
590
- var moduleExports = freeModule && freeModule.exports === freeExports;
591
- var freeProcess = moduleExports && freeGlobal2.process;
592
- var nodeUtil2 = function() {
593
- try {
594
- var types = freeModule && freeModule.require && freeModule.require("util").types;
595
- if (types) {
596
- return types;
597
- }
598
- return freeProcess && freeProcess.binding && freeProcess.binding("util");
599
- } catch (e) {
600
- }
601
- }();
602
- module.exports = nodeUtil2;
603
- })(_nodeUtil, _nodeUtil.exports);
604
- var nodeUtil = _nodeUtil.exports;
605
- nodeUtil && nodeUtil.isTypedArray;
606
- var getNative$3 = _getNative, root$4 = _root;
607
- var DataView$1 = getNative$3(root$4, "DataView");
608
- var _DataView = DataView$1;
609
- var getNative$2 = _getNative, root$3 = _root;
610
- var Promise$2 = getNative$2(root$3, "Promise");
611
- var _Promise = Promise$2;
612
- var getNative$1 = _getNative, root$2 = _root;
613
- var Set$2 = getNative$1(root$2, "Set");
614
- var _Set = Set$2;
615
- var getNative = _getNative, root$1 = _root;
616
- var WeakMap$1 = getNative(root$1, "WeakMap");
617
- var _WeakMap = WeakMap$1;
618
- var DataView = _DataView, Map$1 = _Map, Promise$1 = _Promise, Set$1 = _Set, WeakMap = _WeakMap, baseGetTag = _baseGetTag, toSource = _toSource;
619
- var mapTag = "[object Map]", objectTag = "[object Object]", promiseTag = "[object Promise]", setTag = "[object Set]", weakMapTag = "[object WeakMap]";
620
- var dataViewTag = "[object DataView]";
621
- var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map$1), promiseCtorString = toSource(Promise$1), setCtorString = toSource(Set$1), weakMapCtorString = toSource(WeakMap);
622
- var getTag = baseGetTag;
623
- if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map$1 && getTag(new Map$1()) != mapTag || Promise$1 && getTag(Promise$1.resolve()) != promiseTag || Set$1 && getTag(new Set$1()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
624
- getTag = function(value) {
625
- var result2 = baseGetTag(value), Ctor = result2 == objectTag ? value.constructor : void 0, ctorString = Ctor ? toSource(Ctor) : "";
626
- if (ctorString) {
627
- switch (ctorString) {
628
- case dataViewCtorString:
629
- return dataViewTag;
630
- case mapCtorString:
631
- return mapTag;
632
- case promiseCtorString:
633
- return promiseTag;
634
- case setCtorString:
635
- return setTag;
636
- case weakMapCtorString:
637
- return weakMapTag;
638
- }
639
- }
640
- return result2;
641
- };
642
- }
643
557
  const isDate = (d) => d instanceof Date;
644
558
  const isEmpty = (o) => Object.keys(o).length === 0;
645
559
  const isObject$2 = (o) => o != null && typeof o === "object";
@@ -10469,8 +10383,52 @@ function array_move(arr, old_index, new_index) {
10469
10383
  arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
10470
10384
  return arr;
10471
10385
  }
10386
+ function uiPatch(data, patch) {
10387
+ const ui = Object.assign({}, data._ui || {}, patch);
10388
+ return Object.assign({}, data, { _ui: ui });
10389
+ }
10390
+ function parseAdditionalInformation(payload) {
10391
+ var _a;
10392
+ const raw = (_a = payload == null ? void 0 : payload.additional_information) != null ? _a : payload == null ? void 0 : payload.additional_info;
10393
+ if (raw == null || raw === "")
10394
+ return null;
10395
+ if (typeof raw === "object")
10396
+ return raw;
10397
+ try {
10398
+ return JSON.parse(raw);
10399
+ } catch {
10400
+ return null;
10401
+ }
10402
+ }
10403
+ function itemPathForResourceId(idPath) {
10404
+ const withoutId = idPath.replace(/\.id$/, "");
10405
+ const lastDot = withoutId.lastIndexOf(".");
10406
+ if (lastDot === -1)
10407
+ return withoutId;
10408
+ return withoutId.substring(0, lastDot);
10409
+ }
10410
+ function applyMediaMetadataFromGallery(data, resourceIdPath, payload) {
10411
+ var _a, _b;
10412
+ const info = parseAdditionalInformation(payload);
10413
+ if (!info)
10414
+ return data;
10415
+ const itemPath = itemPathForResourceId(resourceIdPath);
10416
+ const mappings = [
10417
+ ["alt_text", info.alt_text],
10418
+ ["caption", (_a = info.img_title) != null ? _a : info.caption],
10419
+ ["credit", (_b = info.img_credit) != null ? _b : info.credit]
10420
+ ];
10421
+ let result2 = data;
10422
+ mappings.forEach(([field, value]) => {
10423
+ if (value == null || String(value).trim() === "")
10424
+ return;
10425
+ result2 = set_1(result2, `${itemPath}.${field}`, String(value).trim());
10426
+ });
10427
+ return result2;
10428
+ }
10472
10429
  class KubikWidgetController extends Controller {
10473
10430
  connect() {
10431
+ this.syncExpandedFromData();
10474
10432
  this.getNewWidget();
10475
10433
  const element = this.element;
10476
10434
  if (this.expandedValue) {
@@ -10481,10 +10439,38 @@ class KubikWidgetController extends Controller {
10481
10439
  element.addEventListener("keydown", this.handleKeyDown.bind(this));
10482
10440
  element.addEventListener("paste", this.handlePaste.bind(this));
10483
10441
  }
10442
+ syncExpandedFromData() {
10443
+ const ui = this.dataValue._ui || {};
10444
+ if (typeof ui.expanded === "boolean") {
10445
+ this.expandedValue = ui.expanded;
10446
+ } else if (typeof this.dataValue.expanded === "boolean") {
10447
+ this.expandedValue = this.dataValue.expanded;
10448
+ }
10449
+ }
10484
10450
  toggleExpanded() {
10485
10451
  this.expandedValue = !this.expandedValue;
10486
- this.expandedInputTarget.value = this.expandedValue;
10487
- this.dataValue = Object.assign({}, this.dataValue, { expanded: this.expandedValue });
10452
+ if (this.hasExpandedInputTarget) {
10453
+ this.expandedInputTarget.value = this.expandedValue;
10454
+ }
10455
+ this.dataValue = uiPatch(this.dataValue, { expanded: this.expandedValue });
10456
+ }
10457
+ setActiveTab(event) {
10458
+ const tab = event.currentTarget.value;
10459
+ this.dataValue = uiPatch(this.dataValue, { active_tab: tab });
10460
+ }
10461
+ repeaterToggle(event) {
10462
+ var _a;
10463
+ const { tab, index: index2, expanded } = event.detail;
10464
+ if (tab == null || index2 == null)
10465
+ return;
10466
+ const items = [...((_a = this.dataValue[tab]) == null ? void 0 : _a.repeated_items) || []];
10467
+ if (!items[index2])
10468
+ return;
10469
+ items[index2] = Object.assign({}, items[index2], {
10470
+ _ui: Object.assign({}, items[index2]._ui || {}, { expanded })
10471
+ });
10472
+ const tabData = Object.assign({}, this.dataValue[tab], { repeated_items: items });
10473
+ this.dataValue = Object.assign({}, this.dataValue, { [tab]: tabData });
10488
10474
  }
10489
10475
  expandedValueChanged() {
10490
10476
  if (this.expandedValue) {
@@ -10495,7 +10481,7 @@ class KubikWidgetController extends Controller {
10495
10481
  }
10496
10482
  handleKeyDown(event) {
10497
10483
  const element = this.element;
10498
- if (element.contains(document.activeElement) && (event.key === "Tab" || event.key === "Enter")) {
10484
+ if (element.contains(document.activeElement) && event.key === "Enter") {
10499
10485
  event.stopPropagation();
10500
10486
  }
10501
10487
  }
@@ -10551,11 +10537,18 @@ class KubikWidgetController extends Controller {
10551
10537
  this.getNewWidget();
10552
10538
  }
10553
10539
  dataValueChanged(value, previousValue) {
10540
+ if (!previousValue || !value)
10541
+ return;
10554
10542
  const diff = updatedDiff(previousValue, value);
10555
10543
  const changedKeys = deepKeys_1(diff);
10556
- console.log(changedKeys, diff);
10544
+ if (changedKeys.length === 0)
10545
+ return;
10546
+ if (changedKeys.every((key) => key === "_ui" || key.startsWith("_ui."))) {
10547
+ return;
10548
+ }
10557
10549
  const addedItem = diff["items"] && diff["items"]["repeated_items"] && JSON.stringify(Object.values(diff["items"]["repeated_items"])[0]) === JSON.stringify({});
10558
- if (addedItem || changedKeys.filter((key) => key.match(/^id$|\.id$/g)).length > 0) {
10550
+ const resourceIdChange = changedKeys.some((key) => key.match(/(^|\.)id$/));
10551
+ if (addedItem || resourceIdChange) {
10559
10552
  this.getNewWidget();
10560
10553
  }
10561
10554
  }
@@ -10574,11 +10567,6 @@ class KubikWidgetController extends Controller {
10574
10567
  if (event.currentTarget.dataset.checkbox === "true" && event.currentTarget.type === "checkbox") {
10575
10568
  v = Array.from(event.currentTarget.parentElement.parentElement.querySelectorAll(`[name="${event.currentTarget.name}"]`)).map((el) => el.checked ? el.value : null).filter((el) => el !== null);
10576
10569
  }
10577
- if (event.currentTarget.dataset.repeatedKeyValue === "true") {
10578
- const [field, idx, ...rest] = event.currentTarget.name.split(".").reverse();
10579
- const fieldName = [rest.reverse().join("."), idx.toString(), field].join(".");
10580
- get_1(this.dataValue, fieldName, "");
10581
- }
10582
10570
  if (event.currentTarget.dataset.repeated === "true") {
10583
10571
  event.currentTarget.dataset.index;
10584
10572
  const [field, index2, ...rest] = event.currentTarget.name.split(".").reverse();
@@ -10609,7 +10597,13 @@ class KubikWidgetController extends Controller {
10609
10597
  }
10610
10598
  receiveModalReturn(return_value) {
10611
10599
  const returnObject = return_value;
10612
- const duplicateData = set_1(this.dataValue, returnObject["return_payload"]["field_name"], returnObject["payload"]["id"]);
10600
+ const fieldPath = returnObject["return_payload"]["field_name"];
10601
+ let duplicateData = set_1(this.dataValue, fieldPath, returnObject["payload"]["id"]);
10602
+ duplicateData = applyMediaMetadataFromGallery(
10603
+ duplicateData,
10604
+ fieldPath,
10605
+ returnObject["payload"]
10606
+ );
10613
10607
  this.dataValue = duplicateData;
10614
10608
  this.getNewWidget();
10615
10609
  }
@@ -10629,6 +10623,12 @@ class KubikWidgetController extends Controller {
10629
10623
  })
10630
10624
  }).then((response) => response.text()).then((html) => {
10631
10625
  Turbo.renderStreamMessage(html);
10626
+ this.syncExpandedFromData();
10627
+ if (this.expandedValue) {
10628
+ this.element.classList.add(this.expandedClass);
10629
+ } else {
10630
+ this.element.classList.remove(this.expandedClass);
10631
+ }
10632
10632
  });
10633
10633
  }
10634
10634
  }
@@ -10643,26 +10643,42 @@ __publicField(KubikWidgetController, "targets", ["expandedInput"]);
10643
10643
  __publicField(KubikWidgetController, "classes", ["expanded"]);
10644
10644
  class KubikRepeaterController extends Controller {
10645
10645
  connect() {
10646
+ if (this.expandedValue) {
10647
+ this.element.classList.add(this.expandedClass);
10648
+ }
10646
10649
  }
10647
10650
  updateHeader(event) {
10648
10651
  this.headerTarget.innerHTML = event.currentTarget.value;
10649
10652
  }
10650
10653
  toggleItem(event) {
10651
- if (this.element.classList.contains(this.expandedClass)) {
10652
- this.element.classList.remove(this.expandedClass);
10653
- } else {
10654
+ const expanded = !this.element.classList.contains(this.expandedClass);
10655
+ if (expanded) {
10654
10656
  this.element.classList.add(this.expandedClass);
10657
+ } else {
10658
+ this.element.classList.remove(this.expandedClass);
10655
10659
  }
10660
+ this.dispatch("toggle", {
10661
+ prefix: "",
10662
+ detail: {
10663
+ tab: this.tabValue,
10664
+ index: this.indexValue,
10665
+ expanded
10666
+ }
10667
+ });
10656
10668
  }
10657
10669
  }
10658
10670
  __publicField(KubikRepeaterController, "targets", ["header"]);
10659
10671
  __publicField(KubikRepeaterController, "classes", ["expanded"]);
10672
+ __publicField(KubikRepeaterController, "values", {
10673
+ tab: String,
10674
+ index: Number,
10675
+ expanded: { type: Boolean, default: false }
10676
+ });
10660
10677
  class KubikKeyValueRepeaterController extends Controller {
10661
10678
  connect() {
10662
10679
  this.renderFields();
10663
10680
  }
10664
10681
  dataValueChanged() {
10665
- console.log("dataValueChanged", this.dataValue);
10666
10682
  this.dispatch("updateData", {
10667
10683
  detail: {
10668
10684
  fieldName: this.fieldNameValue,
@@ -10936,11 +10952,18 @@ __publicField(KubikAutocompleteController, "values", {
10936
10952
  results: { type: Array, default: [] },
10937
10953
  resultActive: Number
10938
10954
  });
10955
+ function widgetExpanded(data) {
10956
+ if (!data || typeof data !== "object")
10957
+ return false;
10958
+ if (data._ui && typeof data._ui.expanded === "boolean")
10959
+ return data._ui.expanded;
10960
+ return !!data.expanded;
10961
+ }
10939
10962
  const widgetWrapper = function widgetWrapper2(details = {}, data) {
10940
10963
  let wrapperAttributes = {
10941
10964
  "data-controller": "kubik-widget",
10942
10965
  "data-kubik-widget-expanded-class": "kubik-widget__expanded",
10943
- "data-kubik-widget-expanded-value": JSON.stringify(data.expanded) || false,
10966
+ "data-kubik-widget-expanded-value": JSON.stringify(widgetExpanded(data)),
10944
10967
  "data-kubik-widget-setup-value": JSON.stringify(details.setup),
10945
10968
  "data-kubik-widget-data-value": JSON.stringify(data),
10946
10969
  "data-kubik-widget-widget-id-value": details.setup.widget_id,
@@ -10962,6 +10985,11 @@ const widgetWrapper = function widgetWrapper2(details = {}, data) {
10962
10985
  );
10963
10986
  return wrapper;
10964
10987
  };
10988
+ function uiFromData(data) {
10989
+ if (!data || typeof data !== "object")
10990
+ return {};
10991
+ return data._ui && typeof data._ui === "object" ? data._ui : {};
10992
+ }
10965
10993
  class PluginFactory {
10966
10994
  static get defaultWidgetConfig() {
10967
10995
  return {
@@ -10969,7 +10997,7 @@ class PluginFactory {
10969
10997
  };
10970
10998
  }
10971
10999
  constructor({ data, api }) {
10972
- this.data = data;
11000
+ this.data = data || {};
10973
11001
  this.api = api;
10974
11002
  this.randomString = Math.random().toString(36).substring(2, 7);
10975
11003
  this.label = this.constructor.toolbox.title;
@@ -10979,6 +11007,12 @@ class PluginFactory {
10979
11007
  defaultConfig,
10980
11008
  localConfig
10981
11009
  );
11010
+ const ui = uiFromData(this.data);
11011
+ if (this.data.expanded !== void 0 && ui.expanded === void 0) {
11012
+ this.data = Object.assign({}, this.data, {
11013
+ _ui: Object.assign({}, ui, { expanded: this.data.expanded })
11014
+ });
11015
+ }
10982
11016
  }
10983
11017
  render() {
10984
11018
  const widgetId = [this.config.widget_name, this.randomString].join("-");
@@ -11002,17 +11036,232 @@ class PluginFactory {
11002
11036
  this.config.tabs.forEach((tab) => {
11003
11037
  widgetData[tab["name"]] = data[tab["name"]];
11004
11038
  });
11039
+ if (data._ui) {
11040
+ widgetData._ui = data._ui;
11041
+ } else if (data.expanded !== void 0) {
11042
+ widgetData._ui = { expanded: data.expanded };
11043
+ }
11005
11044
  return widgetData;
11006
11045
  }
11007
11046
  validate(savedData) {
11008
11047
  return true;
11009
11048
  }
11010
11049
  }
11050
+ function defineBlock({ toolbox, sanitize = {}, widgetConfig }) {
11051
+ if (!toolbox || !widgetConfig) {
11052
+ throw new Error("defineBlock requires toolbox and widgetConfig");
11053
+ }
11054
+ return class extends PluginFactory {
11055
+ static get toolbox() {
11056
+ return toolbox;
11057
+ }
11058
+ static get sanitize() {
11059
+ return sanitize;
11060
+ }
11061
+ static get widgetConfig() {
11062
+ return widgetConfig;
11063
+ }
11064
+ };
11065
+ }
11066
+ function contentTab(fields = []) {
11067
+ return {
11068
+ name: "content",
11069
+ label: "Content",
11070
+ fields: [
11071
+ { name: "title", label: "Title", type: "text" },
11072
+ { name: "intro", label: "Intro", type: "textarea" },
11073
+ { name: "link", label: "Link", type: "text" },
11074
+ { name: "link_text", label: "Link text", type: "text" },
11075
+ ...fields
11076
+ ]
11077
+ };
11078
+ }
11079
+ function settingsTab({ layouts = [], extras = [] } = {}) {
11080
+ const fields = [];
11081
+ if (layouts.length > 0) {
11082
+ fields.push({
11083
+ name: "layout",
11084
+ label: "Layout",
11085
+ type: "select",
11086
+ options: layouts
11087
+ });
11088
+ }
11089
+ fields.push(
11090
+ { name: "additional_classes", type: "text", label: "Additional classes" },
11091
+ { name: "element_id", type: "text", label: "Element ID" },
11092
+ ...extras
11093
+ );
11094
+ return { name: "settings", label: "Settings", fields };
11095
+ }
11096
+ function standardSettingsExtras() {
11097
+ return [
11098
+ {
11099
+ name: "image_loading",
11100
+ label: "Image loading",
11101
+ type: "select",
11102
+ options: [
11103
+ { value: "lazy", label: "Lazy" },
11104
+ { value: "eager", label: "Eager (above the fold)" }
11105
+ ]
11106
+ },
11107
+ {
11108
+ name: "data_attributes",
11109
+ label: "Data attributes",
11110
+ type: "key_value_repeater",
11111
+ prefix: "data",
11112
+ fields: ["key", "value"]
11113
+ }
11114
+ ];
11115
+ }
11116
+ function thumbAndFieldsSections() {
11117
+ return [
11118
+ { name: "thumb", classes: "thumb" },
11119
+ { name: "fields", classes: "fields" }
11120
+ ];
11121
+ }
11122
+ function manualItemsTab({
11123
+ name = "items",
11124
+ label = "Items",
11125
+ itemFields,
11126
+ addLabel = "Add item",
11127
+ summary = "title",
11128
+ sections = thumbAndFieldsSections()
11129
+ }) {
11130
+ return {
11131
+ name,
11132
+ label,
11133
+ sections,
11134
+ fields: itemFields,
11135
+ repeated: true,
11136
+ repeater_settings: {
11137
+ add_label: addLabel,
11138
+ summary
11139
+ }
11140
+ };
11141
+ }
11142
+ function resourceListSettingsTab({
11143
+ filterField = "filter",
11144
+ filterLabel = "Filter",
11145
+ filterOptions = [],
11146
+ layouts = [],
11147
+ extras = []
11148
+ }) {
11149
+ const fields = [];
11150
+ if (filterOptions.length > 0) {
11151
+ fields.push({
11152
+ name: filterField,
11153
+ label: filterLabel,
11154
+ type: "select",
11155
+ options: filterOptions
11156
+ });
11157
+ }
11158
+ if (layouts.length > 0) {
11159
+ fields.push({
11160
+ name: "layout",
11161
+ label: "Layout",
11162
+ type: "select",
11163
+ options: layouts
11164
+ });
11165
+ }
11166
+ fields.push(
11167
+ { name: "additional_classes", type: "text", label: "Additional classes" },
11168
+ { name: "element_id", type: "text", label: "Element ID" },
11169
+ ...extras
11170
+ );
11171
+ return { name: "settings", label: "Settings", fields };
11172
+ }
11173
+ const presets = {
11174
+ contentTab,
11175
+ settingsTab,
11176
+ standardSettingsExtras,
11177
+ thumbAndFieldsSections,
11178
+ manualItemsTab,
11179
+ resourceListSettingsTab
11180
+ };
11181
+ const DEFAULT_INLINE_TOOLBAR = ["bold", "italic", "underline", "hyperlink"];
11182
+ const WIDGET_INLINE_TOOLBAR = ["underline", "hyperlink"];
11183
+ const EDITORJS_INLINE_ICON_SPRITE_ID = "kubik-editorjs-inline-icons";
11184
+ const EDITORJS_LINK_ICON_SPRITE = `
11185
+ <symbol id="link" viewBox="0 0 14 10">
11186
+ <path d="M6 0v2H5a3 3 0 000 6h1v2H5A5 5 0 115 0h1zm2 0h1a5 5 0 110 10H8V8h1a3 3 0 000-6H8V0zM5 4h4a1 1 0 110 2H5a1 1 0 110-2z"/>
11187
+ </symbol>
11188
+ <symbol id="unlink" viewBox="0 0 15 11">
11189
+ <path d="M13.073 2.099l-1.448 1.448A3 3 0 009 2H8V0h1c1.68 0 3.166.828 4.073 2.099zM6.929 4l-.879.879L7.172 6H5a1 1 0 110-2h1.929zM6 0v2H5a3 3 0 100 6h1v2H5A5 5 0 115 0h1zm6.414 7l2.122 2.121-1.415 1.415L11 8.414l-2.121 2.122L7.464 9.12 9.586 7 7.464 4.879 8.88 3.464 11 5.586l2.121-2.122 1.415 1.415L12.414 7z"/>
11190
+ </symbol>
11191
+ `;
11192
+ function ensureEditorJsInlineIcons() {
11193
+ if (document.getElementById(EDITORJS_INLINE_ICON_SPRITE_ID))
11194
+ return;
11195
+ if (document.getElementById("link"))
11196
+ return;
11197
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
11198
+ svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
11199
+ svg.setAttribute("aria-hidden", "true");
11200
+ svg.style.display = "none";
11201
+ svg.id = EDITORJS_INLINE_ICON_SPRITE_ID;
11202
+ svg.innerHTML = EDITORJS_LINK_ICON_SPRITE;
11203
+ document.body.appendChild(svg);
11204
+ }
11205
+ function buildBaseEditorTools({
11206
+ widgetInlineToolbar = WIDGET_INLINE_TOOLBAR,
11207
+ richInlineToolbar = DEFAULT_INLINE_TOOLBAR
11208
+ } = {}) {
11209
+ return {
11210
+ paragraph: {
11211
+ class: Paragraph,
11212
+ inlineToolbar: widgetInlineToolbar
11213
+ },
11214
+ hyperlink: {
11215
+ class: Hyperlink,
11216
+ config: {}
11217
+ },
11218
+ embed: {
11219
+ class: Embed,
11220
+ config: {
11221
+ services: {
11222
+ youtube: true,
11223
+ vimeo: true,
11224
+ twitter: true,
11225
+ instagram: true
11226
+ }
11227
+ }
11228
+ },
11229
+ header: {
11230
+ class: Header,
11231
+ config: {
11232
+ placeholder: "Add header text",
11233
+ levels: [2, 3, 4, 5, 6],
11234
+ defaultLevel: 2
11235
+ },
11236
+ inlineToolbar: richInlineToolbar
11237
+ },
11238
+ nested_list: {
11239
+ class: NestedList,
11240
+ inlineToolbar: richInlineToolbar
11241
+ },
11242
+ quote: {
11243
+ class: Quote,
11244
+ inlineToolbar: richInlineToolbar,
11245
+ shortcut: "CMD+SHIFT+O",
11246
+ config: {
11247
+ quotePlaceholder: "Enter a quote",
11248
+ captionPlaceholder: "Quote's author"
11249
+ }
11250
+ },
11251
+ underline: Underline
11252
+ };
11253
+ }
11011
11254
  var index = {
11012
11255
  KubikWidgetController,
11013
11256
  KubikRepeaterController,
11014
11257
  KubikKeyValueRepeaterController,
11015
11258
  PluginFactory,
11016
- KubikAutocompleteController
11259
+ KubikAutocompleteController,
11260
+ defineBlock,
11261
+ presets,
11262
+ DEFAULT_INLINE_TOOLBAR,
11263
+ WIDGET_INLINE_TOOLBAR,
11264
+ ensureEditorJsInlineIcons,
11265
+ buildBaseEditorTools
11017
11266
  };
11018
- export { index as default };
11267
+ export { DEFAULT_INLINE_TOOLBAR, KubikAutocompleteController, KubikKeyValueRepeaterController, KubikRepeaterController, KubikWidgetController, PluginFactory, WIDGET_INLINE_TOOLBAR, buildBaseEditorTools, index as default, defineBlock, ensureEditorJsInlineIcons, presets };