@tailor-cms/ce-flashcards-manifest 0.0.1 → 0.0.2

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.cjs CHANGED
@@ -2,41 +2,126 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
+ let uuid = require("uuid");
5
6
  //#region src/index.ts
7
+ const id1 = (0, uuid.v4)();
8
+ const id2 = (0, uuid.v4)();
6
9
  const type = "FLASHCARDS";
7
10
  const name = "Flashcards";
8
- const initState = (_config) => ({});
11
+ const initState = () => ({
12
+ embeds: {},
13
+ items: {
14
+ [id1]: {
15
+ id: id1,
16
+ front: {},
17
+ back: {},
18
+ position: 1
19
+ },
20
+ [id2]: {
21
+ id: id2,
22
+ front: {},
23
+ back: {},
24
+ position: 2
25
+ }
26
+ },
27
+ height: 360
28
+ });
9
29
  const version = "1.0";
10
30
  const ui = {
11
31
  icon: "mdi-cards-outline",
12
32
  forceFullWidth: true
13
33
  };
14
- const isEmpty = (_data) => false;
15
- const mocks = {
16
- displayContexts: [{
17
- name: "Test preset 1",
18
- data: { state: "I have a value" }
19
- }, {
20
- name: "Test preset 2",
21
- data: { state: "I have a different value" }
22
- }],
23
- referencesData: { linked: [{ title: "Mock linked element" }] }
34
+ const isEmpty = (data) => !data.items || Object.keys(data.items).length === 0;
35
+ const ai = {
36
+ Schema: {
37
+ type: "json_schema",
38
+ name: "ce_flashcards",
39
+ schema: {
40
+ type: "object",
41
+ properties: { cards: {
42
+ type: "array",
43
+ minItems: 2,
44
+ items: {
45
+ type: "object",
46
+ properties: {
47
+ front: { type: "string" },
48
+ back: { type: "string" }
49
+ },
50
+ required: ["front", "back"],
51
+ additionalProperties: false
52
+ }
53
+ } },
54
+ required: ["cards"],
55
+ additionalProperties: false
56
+ }
57
+ },
58
+ getPrompt: () => `
59
+ Generate a flashcards content element as an object with the following
60
+ properties:
61
+ {
62
+ "cards": [
63
+ {
64
+ "front": "",
65
+ "back": ""
66
+ }
67
+ ]
68
+ }
69
+ where:
70
+ - 'cards' is an array of flashcard objects where:
71
+ - 'front' is the prompt side of the card (e.g. a question or term).
72
+ - 'back' is the answer side of the card (e.g. the answer or definition).
73
+ `,
74
+ processResponse: (val) => {
75
+ return {
76
+ ...val.cards.reduce((acc, { front, back }, index) => {
77
+ const frontId = (0, uuid.v4)();
78
+ const backId = (0, uuid.v4)();
79
+ const itemId = (0, uuid.v4)();
80
+ acc.embeds[frontId] = {
81
+ id: frontId,
82
+ data: { content: front },
83
+ embedded: true,
84
+ position: 1,
85
+ type: "TIPTAP_HTML"
86
+ };
87
+ acc.embeds[backId] = {
88
+ id: backId,
89
+ data: { content: back },
90
+ embedded: true,
91
+ position: 1,
92
+ type: "TIPTAP_HTML"
93
+ };
94
+ acc.items[itemId] = {
95
+ id: itemId,
96
+ front: { [frontId]: true },
97
+ back: { [backId]: true },
98
+ position: index + 1
99
+ };
100
+ return acc;
101
+ }, {
102
+ items: {},
103
+ embeds: {}
104
+ }),
105
+ height: 360
106
+ };
107
+ }
24
108
  };
25
109
  const manifest = {
26
110
  type,
27
111
  version: "1.0",
28
112
  name,
113
+ isComposite: true,
29
114
  ssr: false,
30
115
  initState,
31
116
  isEmpty,
32
117
  ui,
33
- mocks
118
+ ai
34
119
  };
35
120
  //#endregion
121
+ exports.ai = ai;
36
122
  exports.default = manifest;
37
123
  exports.initState = initState;
38
124
  exports.isEmpty = isEmpty;
39
- exports.mocks = mocks;
40
125
  exports.name = name;
41
126
  exports.type = type;
42
127
  exports.version = version;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,18 @@
1
1
  import * as common from "@tailor-cms/cek-common";
2
- import { ElementMocks } from "@tailor-cms/cek-common";
2
+ import { AiConfig } from "@tailor-cms/cek-common";
3
3
 
4
4
  //#region src/interfaces.d.ts
5
- type ElementData = common.ElementConfig;
5
+ interface FlashcardItem {
6
+ id: string;
7
+ front: Record<string, any>;
8
+ back: Record<string, any>;
9
+ position: number;
10
+ }
11
+ interface ElementData extends common.ElementConfig {
12
+ embeds: Record<string, any>;
13
+ items: Record<string, FlashcardItem>;
14
+ height: number;
15
+ }
6
16
  type DataInitializer = common.DataInitializer<ElementData>;
7
17
  type Element = common.Element<ElementData>;
8
18
  type ElementManifest = common.ElementManifest<ElementData>;
@@ -12,8 +22,8 @@ declare const type = "FLASHCARDS";
12
22
  declare const name = "Flashcards";
13
23
  declare const initState: DataInitializer;
14
24
  declare const version = "1.0";
15
- declare const isEmpty: (_data: ElementData) => boolean;
16
- declare const mocks: ElementMocks;
25
+ declare const isEmpty: (data: ElementData) => boolean;
26
+ declare const ai: AiConfig;
17
27
  declare const manifest: ElementManifest;
18
28
  //#endregion
19
- export { DataInitializer, Element, ElementData, ElementManifest, manifest as default, initState, isEmpty, mocks, name, type, version };
29
+ export { DataInitializer, Element, ElementData, ElementManifest, FlashcardItem, ai, manifest as default, initState, isEmpty, name, type, version };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,18 @@
1
1
  import * as common from "@tailor-cms/cek-common";
2
- import { ElementMocks } from "@tailor-cms/cek-common";
2
+ import { AiConfig } from "@tailor-cms/cek-common";
3
3
 
4
4
  //#region src/interfaces.d.ts
5
- type ElementData = common.ElementConfig;
5
+ interface FlashcardItem {
6
+ id: string;
7
+ front: Record<string, any>;
8
+ back: Record<string, any>;
9
+ position: number;
10
+ }
11
+ interface ElementData extends common.ElementConfig {
12
+ embeds: Record<string, any>;
13
+ items: Record<string, FlashcardItem>;
14
+ height: number;
15
+ }
6
16
  type DataInitializer = common.DataInitializer<ElementData>;
7
17
  type Element = common.Element<ElementData>;
8
18
  type ElementManifest = common.ElementManifest<ElementData>;
@@ -12,8 +22,8 @@ declare const type = "FLASHCARDS";
12
22
  declare const name = "Flashcards";
13
23
  declare const initState: DataInitializer;
14
24
  declare const version = "1.0";
15
- declare const isEmpty: (_data: ElementData) => boolean;
16
- declare const mocks: ElementMocks;
25
+ declare const isEmpty: (data: ElementData) => boolean;
26
+ declare const ai: AiConfig;
17
27
  declare const manifest: ElementManifest;
18
28
  //#endregion
19
- export { DataInitializer, Element, ElementData, ElementManifest, manifest as default, initState, isEmpty, mocks, name, type, version };
29
+ export { DataInitializer, Element, ElementData, ElementManifest, FlashcardItem, ai, manifest as default, initState, isEmpty, name, type, version };
package/dist/index.mjs CHANGED
@@ -1,32 +1,117 @@
1
+ import { v4 } from "uuid";
1
2
  //#region src/index.ts
3
+ const id1 = v4();
4
+ const id2 = v4();
2
5
  const type = "FLASHCARDS";
3
6
  const name = "Flashcards";
4
- const initState = (_config) => ({});
7
+ const initState = () => ({
8
+ embeds: {},
9
+ items: {
10
+ [id1]: {
11
+ id: id1,
12
+ front: {},
13
+ back: {},
14
+ position: 1
15
+ },
16
+ [id2]: {
17
+ id: id2,
18
+ front: {},
19
+ back: {},
20
+ position: 2
21
+ }
22
+ },
23
+ height: 360
24
+ });
5
25
  const version = "1.0";
6
26
  const ui = {
7
27
  icon: "mdi-cards-outline",
8
28
  forceFullWidth: true
9
29
  };
10
- const isEmpty = (_data) => false;
11
- const mocks = {
12
- displayContexts: [{
13
- name: "Test preset 1",
14
- data: { state: "I have a value" }
15
- }, {
16
- name: "Test preset 2",
17
- data: { state: "I have a different value" }
18
- }],
19
- referencesData: { linked: [{ title: "Mock linked element" }] }
30
+ const isEmpty = (data) => !data.items || Object.keys(data.items).length === 0;
31
+ const ai = {
32
+ Schema: {
33
+ type: "json_schema",
34
+ name: "ce_flashcards",
35
+ schema: {
36
+ type: "object",
37
+ properties: { cards: {
38
+ type: "array",
39
+ minItems: 2,
40
+ items: {
41
+ type: "object",
42
+ properties: {
43
+ front: { type: "string" },
44
+ back: { type: "string" }
45
+ },
46
+ required: ["front", "back"],
47
+ additionalProperties: false
48
+ }
49
+ } },
50
+ required: ["cards"],
51
+ additionalProperties: false
52
+ }
53
+ },
54
+ getPrompt: () => `
55
+ Generate a flashcards content element as an object with the following
56
+ properties:
57
+ {
58
+ "cards": [
59
+ {
60
+ "front": "",
61
+ "back": ""
62
+ }
63
+ ]
64
+ }
65
+ where:
66
+ - 'cards' is an array of flashcard objects where:
67
+ - 'front' is the prompt side of the card (e.g. a question or term).
68
+ - 'back' is the answer side of the card (e.g. the answer or definition).
69
+ `,
70
+ processResponse: (val) => {
71
+ return {
72
+ ...val.cards.reduce((acc, { front, back }, index) => {
73
+ const frontId = v4();
74
+ const backId = v4();
75
+ const itemId = v4();
76
+ acc.embeds[frontId] = {
77
+ id: frontId,
78
+ data: { content: front },
79
+ embedded: true,
80
+ position: 1,
81
+ type: "TIPTAP_HTML"
82
+ };
83
+ acc.embeds[backId] = {
84
+ id: backId,
85
+ data: { content: back },
86
+ embedded: true,
87
+ position: 1,
88
+ type: "TIPTAP_HTML"
89
+ };
90
+ acc.items[itemId] = {
91
+ id: itemId,
92
+ front: { [frontId]: true },
93
+ back: { [backId]: true },
94
+ position: index + 1
95
+ };
96
+ return acc;
97
+ }, {
98
+ items: {},
99
+ embeds: {}
100
+ }),
101
+ height: 360
102
+ };
103
+ }
20
104
  };
21
105
  const manifest = {
22
106
  type,
23
107
  version: "1.0",
24
108
  name,
109
+ isComposite: true,
25
110
  ssr: false,
26
111
  initState,
27
112
  isEmpty,
28
113
  ui,
29
- mocks
114
+ ai
30
115
  };
31
116
  //#endregion
32
- export { manifest as default, initState, isEmpty, mocks, name, type, version };
117
+ export { ai, manifest as default, initState, isEmpty, name, type, version };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Tailor CMS flashcards element manifest",
4
4
  "author": "Studion <info@gostudion.com> (https://github.com/tailor-cms)",
5
5
  "type": "module",
6
- "version": "0.0.1",
6
+ "version": "0.0.2",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.mjs",
@@ -16,7 +16,8 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@tailor-cms/cek-common": "^2.0.1"
19
+ "@tailor-cms/cek-common": "^2.0.1",
20
+ "uuid": "^14.0.0"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@tailor-cms/eslint-config": "^2.0.1",