directus-extension-texttoanything 1.0.1 → 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.
Files changed (3) hide show
  1. package/dist/app.js +250 -40
  2. package/package.json +4 -1
  3. package/readme.md +1 -1
package/dist/app.js CHANGED
@@ -340,6 +340,234 @@ var e3 = defineOperationApp({
340
340
  ]
341
341
  });
342
342
 
343
+ const tagName = String.raw`[A-Za-z][^/\s>]*`;
344
+
345
+ // Preserve strings in templates and such
346
+ // Avoid apostrophes and unintentional captures
347
+ const doubleQuotedString = String.raw`(?<!\w)"(?:\\[^<>\n]|[^\\"<>\n])*"(?!\w)`;
348
+ const singleQuotedString = String.raw`(?<!\w)'(?:\\[^<>\n]|[^\\'<>\n])*'(?!\w)`;
349
+ const quotedString = String.raw`${doubleQuotedString}|${singleQuotedString}`;
350
+
351
+ const quotedAttrValue = String.raw`"(?<quotedAttrValue>[^"]*)"`;
352
+ const singleQuotedAttrValue = String.raw`'(?<singleQuotedAttrValue>[^']*)'`;
353
+ // https://mothereff.in/unquoted-attributes
354
+ const unquotedAttrValue = String.raw`(?<unquotedAttrValue>[^\s"'\`=<>]+)`;
355
+
356
+ const attrName = String.raw`[^=\s>/"']+(?=[=>\s]|$)`;
357
+ const attrValue = String.raw`${quotedAttrValue}|${singleQuotedAttrValue}|${unquotedAttrValue}`;
358
+ const attrNameValue = String.raw`(?<attrName>${attrName})(?:\s*=\s*(?:${attrValue}))?`;
359
+
360
+ // Make sure not to swallow the closing slash if one exists
361
+ const attrText = String.raw`${quotedString}|[^\s>]*[^\s>/]|[^\s>]*/(?!\s*>)`;
362
+
363
+ const attr = String.raw`(?<attrSpace>\s*)(?:${attrNameValue}|(?<attrText>${attrText}))`;
364
+
365
+ const tokens = {
366
+ comment: String.raw`<!--.*?-->`,
367
+ dtd: String.raw`<![^>]+>`,
368
+ startTag: String.raw`<(?<startTagName>${tagName})(?<attrs>(?:${attr})*)\s*(?<closingSlash>/?)\s*>`,
369
+ endTag: String.raw`</(?<endTagName>${tagName})\s*>`,
370
+ space: String.raw`\s+`,
371
+ text: String.raw`[^<\s"']+|${quotedString}|['"]`,
372
+ wildcard: String.raw`.`,
373
+ };
374
+
375
+ const grammar = Object.entries(tokens)
376
+ .map(([k, v]) => `(?<${k}>${v})`)
377
+ .join("|");
378
+
379
+ /**
380
+ *
381
+ * @param {RegExp} lexer
382
+ * @param {string} s
383
+ */
384
+ function* getTokens(lexer, s) {
385
+ let res;
386
+ let { lastIndex } = lexer;
387
+ while ((res = lexer.exec(s))) {
388
+ yield /** @type {RegExpExecArray & { groups: Record<string, string> }} */ (
389
+ res
390
+ );
391
+ ({ lastIndex } = lexer);
392
+ }
393
+ if (lastIndex != s.length) throw new Error("Failed to parse string");
394
+ }
395
+
396
+ const voidTags = new Set([
397
+ "area",
398
+ "base",
399
+ "basefont",
400
+ "bgsound",
401
+ "br",
402
+ "col",
403
+ "command",
404
+ "embed",
405
+ "frame",
406
+ "hr",
407
+ "image",
408
+ "img",
409
+ "input",
410
+ "keygen",
411
+ "link",
412
+ "meta",
413
+ "param",
414
+ "source",
415
+ "track",
416
+ "wbr",
417
+ ]);
418
+
419
+ function format(/** @type {string} */ html, indent = " ", width = 80) {
420
+ const lexer = new RegExp(grammar, "gys");
421
+ const attrLexer = new RegExp(attr, "gy");
422
+
423
+ /** @type {string[]} */
424
+ const output = [];
425
+
426
+ /** @type {string | null} */
427
+ let specialElement = null;
428
+ let level = 0;
429
+
430
+ let lineLength = 0;
431
+ let span = "";
432
+ let spanLevel = 0;
433
+ let lastSpace = "";
434
+
435
+ const flushOutput = () => {
436
+ if (lastSpace && lastSpace != "\n") {
437
+ const newline = span.indexOf("\n");
438
+ const len = newline == -1 ? span.length : newline;
439
+ if (lineLength + lastSpace.length + len > width) lastSpace = "\n";
440
+ }
441
+
442
+ const ind = lastSpace == "\n" && span ? indent.repeat(spanLevel) : "";
443
+ const out = `${lastSpace}${ind}${span}`;
444
+
445
+ if (out) {
446
+ const pos = out.lastIndexOf("\n");
447
+ if (pos == -1) lineLength += out.length;
448
+ else lineLength = out.length - pos - 1;
449
+ output.push(out);
450
+ }
451
+
452
+ span = lastSpace = "";
453
+ };
454
+
455
+ const addOutput = (/** @type {string[]} */ ...args) => {
456
+ for (const s of args) {
457
+ if (!specialElement && /^\s+$/.test(s)) {
458
+ flushOutput();
459
+ lastSpace = s;
460
+ } else {
461
+ if (!span) spanLevel = level;
462
+ span += s;
463
+ }
464
+ }
465
+ };
466
+
467
+ for (const token of getTokens(lexer, html)) {
468
+ // For testing
469
+ if (/** @type {any} */ (format).__strict && token.groups.wildcard)
470
+ throw new Error("Unexpected wildcard");
471
+
472
+ if (token.groups.endTag) {
473
+ const tagName = token.groups.endTagName.toLowerCase();
474
+ if (tagName == specialElement) specialElement = null;
475
+ if (!specialElement) {
476
+ --level;
477
+ addOutput(`</${tagName}>`);
478
+ }
479
+ }
480
+
481
+ if (!specialElement) {
482
+ if (token.groups.space) {
483
+ addOutput(...(token[0].match(/\n/g)?.slice(0, 2) ?? [" "]));
484
+ } else if (
485
+ token.groups.comment ||
486
+ token.groups.dtd ||
487
+ token.groups.text ||
488
+ token.groups.wildcard
489
+ ) {
490
+ addOutput(token[0]);
491
+ } else if (token.groups.startTag) {
492
+ const tagName = token.groups.startTagName.toLowerCase();
493
+
494
+ addOutput(`<${tagName}`);
495
+
496
+ ++level;
497
+
498
+ if (token.groups.attrs) {
499
+ let { lastIndex } = attrLexer;
500
+ let attrToken;
501
+ let lastToken;
502
+ while (
503
+ (attrToken =
504
+ /** @type {RegExpExecArray & { groups: Record<string, string> }} */ (
505
+ attrLexer.exec(token.groups.attrs)
506
+ ))
507
+ ) {
508
+ ({ lastIndex } = attrLexer);
509
+
510
+ // For testing
511
+ if (
512
+ /** @type {any} */ (format).__strict &&
513
+ attrToken.groups.attrText
514
+ )
515
+ throw new Error("Unexpected attr text");
516
+
517
+ if (attrToken.groups.attrText) {
518
+ if (attrToken.groups.attrSpace)
519
+ addOutput(/\n/.test(attrToken.groups.attrSpace) ? "\n" : " ");
520
+ addOutput(attrToken.groups.attrText);
521
+ } else {
522
+ if (attrToken.groups.attrSpace || !lastToken?.groups.attrText)
523
+ addOutput(/\n/.test(attrToken.groups.attrSpace) ? "\n" : " ");
524
+ addOutput(
525
+ `${attrToken.groups.attrName}${
526
+ attrToken.groups.quotedAttrValue
527
+ ? `="${attrToken.groups.quotedAttrValue}"`
528
+ : attrToken.groups.singleQuotedAttrValue
529
+ ? `='${attrToken.groups.singleQuotedAttrValue}'`
530
+ : attrToken.groups.unquotedAttrValue
531
+ ? `=${attrToken.groups.unquotedAttrValue}`
532
+ : ""
533
+ }`
534
+ );
535
+ }
536
+
537
+ lastToken = attrToken;
538
+ }
539
+ if (lastIndex != token.groups.attrs.length)
540
+ throw new Error("Failed to parse attributes");
541
+ }
542
+
543
+ const hasClosingSlash = Boolean(token.groups.closingSlash);
544
+
545
+ addOutput(hasClosingSlash ? " />" : ">");
546
+
547
+ if (hasClosingSlash || voidTags.has(tagName)) --level;
548
+ else if (["pre", "textarea", "script", "style"].includes(tagName))
549
+ specialElement = tagName;
550
+ }
551
+ } else addOutput(token[0]);
552
+ }
553
+
554
+ // Flush remaining output
555
+ flushOutput();
556
+
557
+ let newline = false;
558
+ while (/^\s+$/.test(output[output.length - 1])) {
559
+ const last = /** @type {string} */ (output.pop());
560
+ if (/\n/.test(last)) newline = true;
561
+ }
562
+
563
+ if (newline) output.push("\n");
564
+
565
+ return output.join("");
566
+ }
567
+
568
+ format.default = format;
569
+ var htmlFormat = format;
570
+
343
571
  function render(_ctx, _cache) {
344
572
  const _component_v_icon = resolveComponent("v-icon");
345
573
  const _component_v_list_item_icon = resolveComponent("v-list-item-icon");
@@ -401,15 +629,15 @@ const _hoisted_1$1 = {
401
629
  class: "TTA-popup"
402
630
  };
403
631
  const _hoisted_2$1 = { class: "TTA-toolbar" };
404
- const _hoisted_3$1 = { class: "right-side" };
405
- const _hoisted_4$1 = { class: "setwidth" };
632
+ const _hoisted_3 = { class: "right-side" };
633
+ const _hoisted_4 = { class: "setwidth" };
406
634
  const _hoisted_5 = { class: "TTA-action" };
407
635
  const _hoisted_6 = { class: "TTA-wapper" };
408
- const _hoisted_7 = ["srcdoc"];
636
+ const _hoisted_7 = ["src"];
409
637
  var script$3 = /* @__PURE__ */ defineComponent({
410
638
  __name: "templates",
411
639
  setup(__props) {
412
- const templates = ref([]), templateDetails = ref(false), editTemplate = ref(false), assetsKey = ref("");
640
+ const templates = ref([]), templateDetails = ref(false), editTemplate = ref(false);
413
641
  const widthPartition = ref(50);
414
642
  const previewWidth = computed(() => {
415
643
  return 100 - widthPartition.value;
@@ -436,11 +664,9 @@ var script$3 = /* @__PURE__ */ defineComponent({
436
664
  }));
437
665
  });
438
666
  const computedTemplate = computed(() => {
439
- return `${currentTemplate.value.template}`;
667
+ return "data:text/html;charset=utf-8," + encodeURIComponent(`${currentTemplate.value.template}`);
440
668
  });
441
669
  onMounted(async () => {
442
- const settings = await api.get("/settings");
443
- assetsKey.value = settings.data.data.TTA_ASSETS_KEY;
444
670
  widthPartition.value = parseInt(
445
671
  localStorage.getItem("TTA-widthPartition") || "50"
446
672
  );
@@ -491,6 +717,9 @@ var script$3 = /* @__PURE__ */ defineComponent({
491
717
  };
492
718
  editTemplate.value = false;
493
719
  }
720
+ function alignHTML() {
721
+ currentTemplate.value.template = htmlFormat(currentTemplate.value.template);
722
+ }
494
723
  return (_ctx, _cache) => {
495
724
  const _component_v_icon = resolveComponent("v-icon");
496
725
  const _component_v_button = resolveComponent("v-button");
@@ -678,14 +907,20 @@ var script$3 = /* @__PURE__ */ defineComponent({
678
907
  createTextVNode(toDisplayString(currentTemplate.value.name) + " ", 1),
679
908
  createVNode(_component_v_icon, { name: "edit" })
680
909
  ]),
681
- createElementVNode("div", _hoisted_3$1, [
910
+ createElementVNode("div", _hoisted_3, [
911
+ createElementVNode("div", {
912
+ class: "TTA-action",
913
+ onClick: alignHTML
914
+ }, [
915
+ createVNode(_component_v_icon, { name: "vertical_align_center" })
916
+ ]),
682
917
  createElementVNode("div", {
683
918
  class: "TTA-action",
684
919
  onClick: saveTemplate
685
920
  }, [
686
921
  createVNode(_component_v_icon, { name: "save" })
687
922
  ]),
688
- createElementVNode("div", _hoisted_4$1, [
923
+ createElementVNode("div", _hoisted_4, [
689
924
  createVNode(_component_v_slider, {
690
925
  modelValue: widthPartition.value,
691
926
  "onUpdate:modelValue": _cache[9] || (_cache[9] = ($event) => widthPartition.value = $event),
@@ -703,16 +938,16 @@ var script$3 = /* @__PURE__ */ defineComponent({
703
938
  ])
704
939
  ]),
705
940
  createElementVNode("div", _hoisted_6, [
706
- (openBlock(), createBlock(resolveDynamicComponent("interface-input-rich-text-html"), {
941
+ (openBlock(), createBlock(resolveDynamicComponent("interface-input-code"), {
707
942
  class: "TTA-editor",
708
943
  value: currentTemplate.value.template,
709
- imageToken: assetsKey.value,
944
+ language: "htmlmixed",
710
945
  onInput: _cache[10] || (_cache[10] = (html) => currentTemplate.value.template = html),
711
946
  style: normalizeStyle("width: " + unref(editorWidth) + "%")
712
- }, null, 40, ["value", "imageToken", "style"])),
947
+ }, null, 40, ["value", "style"])),
713
948
  createElementVNode("iframe", {
714
949
  class: "TTA-preview",
715
- srcdoc: unref(computedTemplate),
950
+ src: unref(computedTemplate),
716
951
  style: normalizeStyle("width: " + unref(previewWidth) + "%")
717
952
  }, null, 12, _hoisted_7)
718
953
  ])
@@ -748,7 +983,7 @@ var script$3 = /* @__PURE__ */ defineComponent({
748
983
 
749
984
  var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
750
985
 
751
- var css$1 = "\n.TTA-popup {\n position: fixed;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 100;\n display: flex;\n flex-direction: column;\n background-color: var(--background-subdued);\n}\n.TTA-toolbar {\n background-color: var(--background-subdued);\n display: flex;\n justify-content: space-between;\n}\n.TTA-toolbar .right-side {\n display: flex;\n gap: 5px;\n}\n.TTA-toolbar .TTA-slider {\n padding-top: 5px;\n}\n.TTA-toolbar .TTA-action {\n padding: 5px;\n cursor: pointer;\n}\n.TTA-toolbar .setwidth {\n display: flex;\n gap: 10px;\n padding-top: 6px;\n}\n.TTA-toolbar .TTA-template-title {\n margin: auto 0;\n font-size: 18px;\n cursor: pointer;\n padding-right: 5px;\n padding-left: 20px;\n border-bottom: 1px solid var(--v-list-item-border-color);\n}\n.TTA-toolbar .TTA-template-title i {\n padding-left: 5px;\n}\n.TTA-wapper {\n display: flex;\n flex-grow: 1;\n}\n.TTA-preview {\n flex-grow: 1;\n background-color: white;\n border: 0;\n}\n.TTA-editor {\n flex-grow: 1;\n height: 100%;\n}\n.TTA-editor .tox.tox-tinymce {\n height: 100% !important;\n border-radius: 0 !important;\n}\n";
986
+ var css$1 = "\n.TTA-popup {\n position: fixed;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 100;\n display: flex;\n flex-direction: column;\n background-color: var(--background-subdued);\n}\n.TTA-toolbar {\n background-color: var(--background-subdued);\n display: flex;\n justify-content: space-between;\n}\n.TTA-toolbar .right-side {\n display: flex;\n gap: 5px;\n}\n.TTA-toolbar .TTA-slider {\n padding-top: 5px;\n}\n.TTA-toolbar .TTA-action {\n padding: 5px;\n cursor: pointer;\n}\n.TTA-toolbar .setwidth {\n display: flex;\n gap: 10px;\n padding-top: 6px;\n}\n.TTA-toolbar .TTA-template-title {\n margin: auto 0;\n font-size: 18px;\n cursor: pointer;\n padding-right: 5px;\n padding-left: 20px;\n border-bottom: 1px solid var(--v-list-item-border-color);\n}\n.TTA-toolbar .TTA-template-title i {\n padding-left: 5px;\n}\n.TTA-wapper {\n display: flex;\n flex-grow: 1;\n overflow: hidden;\n}\n.TTA-preview {\n flex-grow: 1;\n background-color: white;\n border: 0;\n}\n.TTA-editor {\n flex-grow: 1;\n height: 100%;\n}\n.TTA-editor > div {\n height: 100% !important;\n border-radius: 0 !important;\n}\n.TTA-editor .CodeMirror {\n height: 100%;\n}\n";
752
987
  n(css$1,{});
753
988
 
754
989
  script$3.__file = "settingsmodule/src/templates.vue";
@@ -756,22 +991,16 @@ script$3.__file = "settingsmodule/src/templates.vue";
756
991
  const _withScopeId = (n) => (pushScopeId("data-v-014dce90"), n = n(), popScopeId(), n);
757
992
  const _hoisted_1 = { class: "px-5" };
758
993
  const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "field-name" }, "RapidAPI token", -1));
759
- const _hoisted_3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "field-name" }, "Directus Assets token", -1));
760
- const _hoisted_4 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "field-name" }, "Directus Assets folder", -1));
761
994
  var script$2 = /* @__PURE__ */ defineComponent({
762
995
  __name: "settings",
763
996
  setup(__props) {
764
997
  const rapidKey = ref("");
765
- const assetsKey = ref("");
766
- const assetsFolder = ref("");
767
998
  const saving = ref(false);
768
999
  const api = useApi();
769
1000
  const folder = ref([]);
770
1001
  onMounted(async () => {
771
1002
  const settings = await api.get("/settings");
772
1003
  rapidKey.value = settings.data.data.TTA_KEY;
773
- assetsKey.value = settings.data.data.TTA_ASSETS_KEY;
774
- assetsFolder.value = settings.data.data.TTA_ASSETS_FOLDER;
775
1004
  const folders = await api.get("/folders");
776
1005
  folder.value = folders.data.data.map((e) => ({
777
1006
  text: e.name,
@@ -781,9 +1010,7 @@ var script$2 = /* @__PURE__ */ defineComponent({
781
1010
  async function saveSettings() {
782
1011
  saving.value = true;
783
1012
  await api.patch("/settings", {
784
- TTA_KEY: rapidKey.value,
785
- TTA_ASSETS_KEY: assetsKey.value,
786
- TTA_ASSETS_FOLDER: assetsFolder.value
1013
+ TTA_KEY: rapidKey.value
787
1014
  });
788
1015
  setTimeout(() => {
789
1016
  saving.value = false;
@@ -792,7 +1019,6 @@ var script$2 = /* @__PURE__ */ defineComponent({
792
1019
  return (_ctx, _cache) => {
793
1020
  const _component_v_card_title = resolveComponent("v-card-title");
794
1021
  const _component_v_input = resolveComponent("v-input");
795
- const _component_v_select = resolveComponent("v-select");
796
1022
  const _component_v_card_text = resolveComponent("v-card-text");
797
1023
  const _component_v_icon = resolveComponent("v-icon");
798
1024
  const _component_v_button = resolveComponent("v-button");
@@ -822,22 +1048,6 @@ var script$2 = /* @__PURE__ */ defineComponent({
822
1048
  modelValue: rapidKey.value,
823
1049
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => rapidKey.value = $event)
824
1050
  }, null, 8, ["modelValue"])
825
- ]),
826
- createElementVNode("div", null, [
827
- _hoisted_3,
828
- createVNode(_component_v_input, {
829
- modelValue: assetsKey.value,
830
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => assetsKey.value = $event)
831
- }, null, 8, ["modelValue"])
832
- ]),
833
- createElementVNode("div", null, [
834
- _hoisted_4,
835
- createVNode(_component_v_select, {
836
- modelValue: assetsFolder.value,
837
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => assetsFolder.value = $event),
838
- items: folder.value,
839
- placeholder: "Assets folder"
840
- }, null, 8, ["modelValue", "items"])
841
1051
  ])
842
1052
  ]),
843
1053
  _: 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-extension-texttoanything",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "keywords": [
5
5
  "directus",
6
6
  "directus-extension",
@@ -76,5 +76,8 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@directus/extensions-sdk": "9.22.1"
79
+ },
80
+ "dependencies": {
81
+ "html-format": "^1.1.6"
79
82
  }
80
83
  }
package/readme.md CHANGED
@@ -11,7 +11,7 @@ This extension bundle offers the required operations to achieve that!
11
11
  The package currently supports the following operations:
12
12
 
13
13
  - Create a PDF based on the provided HTML
14
- - Create a HTML Template to PDF
14
+ - Create a PDF based on a HTML Template
15
15
  - Create a QRCode
16
16
  - Create a Barcode
17
17