@tailor-cms/ce-table-manifest 0.0.3 → 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/chunk-CfYAbeIz.mjs +13 -0
- package/dist/index.cjs +177 -118
- package/dist/index.d.cts +32 -79
- package/dist/index.d.mts +48 -0
- package/dist/index.mjs +164 -0
- package/package.json +25 -28
- package/dist/index.d.ts +0 -97
- package/dist/index.js +0 -100
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
package/dist/index.cjs
CHANGED
|
@@ -1,133 +1,192 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
2
6
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
7
|
+
var __exportAll = (all, no_symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// src/index.ts
|
|
30
|
-
var index_exports = {};
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
Direction: () => Direction,
|
|
33
|
-
default: () => index_default,
|
|
34
|
-
initState: () => initState,
|
|
35
|
-
name: () => name,
|
|
36
|
-
type: () => type,
|
|
37
|
-
utils: () => utils_exports,
|
|
38
|
-
version: () => version
|
|
16
|
+
//#endregion
|
|
17
|
+
let lodash_es = require("lodash-es");
|
|
18
|
+
let uuid = require("uuid");
|
|
19
|
+
//#region src/utils.ts
|
|
20
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
addCell: () => addCell,
|
|
22
|
+
addEmbed: () => addEmbed,
|
|
23
|
+
removeCell: () => removeCell,
|
|
24
|
+
removeEmbed: () => removeEmbed
|
|
39
25
|
});
|
|
40
|
-
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
var import_times = __toESM(require("lodash/times"), 1);
|
|
42
|
-
var import_uuid = require("uuid");
|
|
43
|
-
|
|
44
|
-
// src/utils.ts
|
|
45
|
-
var utils_exports = {};
|
|
46
|
-
__export(utils_exports, {
|
|
47
|
-
addCell: () => addCell,
|
|
48
|
-
addEmbed: () => addEmbed,
|
|
49
|
-
removeCell: () => removeCell,
|
|
50
|
-
removeEmbed: () => removeEmbed
|
|
51
|
-
});
|
|
52
|
-
var import_find = __toESM(require("lodash/find"), 1);
|
|
53
26
|
function addCell(row, cell) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
if (!row.cells) row.cells = {};
|
|
28
|
+
row.cells[cell.id] = cell;
|
|
29
|
+
return cell;
|
|
57
30
|
}
|
|
58
31
|
function removeCell(row, predicate = {}) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
const cell = (0, lodash_es.find)(row.cells, predicate);
|
|
33
|
+
if (!cell) return;
|
|
34
|
+
delete row.cells[cell.id];
|
|
35
|
+
return cell;
|
|
63
36
|
}
|
|
64
37
|
function addEmbed(embeds, cellId, tableId) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
38
|
+
const embed = {
|
|
39
|
+
id: cellId,
|
|
40
|
+
type: "JODIT_HTML",
|
|
41
|
+
embedded: true,
|
|
42
|
+
data: {
|
|
43
|
+
tableId,
|
|
44
|
+
cellId
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
embeds[cellId] = embed;
|
|
48
|
+
return embed;
|
|
73
49
|
}
|
|
74
50
|
function removeEmbed(embeds, predicate = {}) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
const embed = (0, lodash_es.find)(embeds, predicate);
|
|
52
|
+
if (!embed) return;
|
|
53
|
+
delete embeds[embed.id];
|
|
54
|
+
return embed;
|
|
79
55
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/interfaces.ts
|
|
58
|
+
let Direction = /* @__PURE__ */ function(Direction) {
|
|
59
|
+
Direction[Direction["Before"] = -1] = "Before";
|
|
60
|
+
Direction[Direction["After"] = 1] = "After";
|
|
61
|
+
return Direction;
|
|
62
|
+
}({});
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/index.ts
|
|
65
|
+
const type = "TABLE";
|
|
66
|
+
const name = "Table";
|
|
67
|
+
const initState = () => {
|
|
68
|
+
const tableId = (0, uuid.v4)();
|
|
69
|
+
const embeds = {};
|
|
70
|
+
const rows = {};
|
|
71
|
+
(0, lodash_es.times)(2, (position) => {
|
|
72
|
+
const rowId = (0, uuid.v4)();
|
|
73
|
+
const row = {
|
|
74
|
+
id: rowId,
|
|
75
|
+
position,
|
|
76
|
+
cells: {}
|
|
77
|
+
};
|
|
78
|
+
rows[rowId] = row;
|
|
79
|
+
(0, lodash_es.times)(3, (position) => {
|
|
80
|
+
const cellId = (0, uuid.v4)();
|
|
81
|
+
addCell(row, {
|
|
82
|
+
id: cellId,
|
|
83
|
+
position,
|
|
84
|
+
data: {}
|
|
85
|
+
});
|
|
86
|
+
addEmbed(embeds, cellId, tableId);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
tableId,
|
|
91
|
+
embeds,
|
|
92
|
+
rows
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const version = "1.0";
|
|
96
|
+
const ui = {
|
|
97
|
+
icon: "mdi-table",
|
|
98
|
+
forceFullWidth: true
|
|
106
99
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
const isEmpty = (data) => !data?.rows || Object.keys(data.rows).length === 0;
|
|
101
|
+
const ai = {
|
|
102
|
+
Schema: {
|
|
103
|
+
type: "json_schema",
|
|
104
|
+
name: "ce_table",
|
|
105
|
+
schema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: { rows: {
|
|
108
|
+
type: "array",
|
|
109
|
+
minItems: 1,
|
|
110
|
+
items: {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: { cells: {
|
|
113
|
+
type: "array",
|
|
114
|
+
minItems: 1,
|
|
115
|
+
items: { type: "string" }
|
|
116
|
+
} },
|
|
117
|
+
required: ["cells"],
|
|
118
|
+
additionalProperties: false
|
|
119
|
+
}
|
|
120
|
+
} },
|
|
121
|
+
required: ["rows"],
|
|
122
|
+
additionalProperties: false
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
getPrompt: () => `
|
|
126
|
+
Generate a table content element as an object with the following
|
|
127
|
+
properties:
|
|
128
|
+
{
|
|
129
|
+
"rows": [
|
|
130
|
+
{ "cells": ["", ""] }
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
where:
|
|
134
|
+
- 'rows' is an array of row objects.
|
|
135
|
+
- each row has a 'cells' array of plain text strings (one per cell).
|
|
136
|
+
Every row must have the same number of cells.
|
|
137
|
+
`,
|
|
138
|
+
processResponse: (val) => {
|
|
139
|
+
const tableId = (0, uuid.v4)();
|
|
140
|
+
const rows = {};
|
|
141
|
+
const embeds = {};
|
|
142
|
+
val.rows.forEach((row, rowPosition) => {
|
|
143
|
+
const rowId = (0, uuid.v4)();
|
|
144
|
+
rows[rowId] = {
|
|
145
|
+
id: rowId,
|
|
146
|
+
position: rowPosition,
|
|
147
|
+
cells: {}
|
|
148
|
+
};
|
|
149
|
+
row.cells.forEach((content, cellPosition) => {
|
|
150
|
+
const cellId = (0, uuid.v4)();
|
|
151
|
+
addCell(rows[rowId], {
|
|
152
|
+
id: cellId,
|
|
153
|
+
position: cellPosition,
|
|
154
|
+
data: {}
|
|
155
|
+
});
|
|
156
|
+
const embed = addEmbed(embeds, cellId, tableId);
|
|
157
|
+
embed.data.content = content;
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
tableId,
|
|
162
|
+
rows,
|
|
163
|
+
embeds
|
|
164
|
+
};
|
|
165
|
+
}
|
|
114
166
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
167
|
+
const manifest = {
|
|
168
|
+
type,
|
|
169
|
+
version: "1.0",
|
|
170
|
+
name,
|
|
171
|
+
ssr: false,
|
|
172
|
+
isComposite: true,
|
|
173
|
+
initState,
|
|
174
|
+
isEmpty,
|
|
175
|
+
ui,
|
|
176
|
+
ai
|
|
123
177
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
exports.Direction = Direction;
|
|
180
|
+
exports.ai = ai;
|
|
181
|
+
exports.default = manifest;
|
|
182
|
+
exports.initState = initState;
|
|
183
|
+
exports.isEmpty = isEmpty;
|
|
184
|
+
exports.name = name;
|
|
185
|
+
exports.type = type;
|
|
186
|
+
Object.defineProperty(exports, "utils", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function() {
|
|
189
|
+
return utils_exports;
|
|
190
|
+
}
|
|
133
191
|
});
|
|
192
|
+
exports.version = version;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,97 +1,50 @@
|
|
|
1
|
+
import * as common from "@tailor-cms/cek-common";
|
|
2
|
+
import { AiConfig } from "@tailor-cms/cek-common";
|
|
3
|
+
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/interfaces.d.ts
|
|
1
7
|
declare enum Direction {
|
|
2
|
-
|
|
3
|
-
|
|
8
|
+
Before = -1,
|
|
9
|
+
After = 1
|
|
4
10
|
}
|
|
5
11
|
type Embed = any;
|
|
6
12
|
type Embeds = Record<string, Embed>;
|
|
7
13
|
interface Cell {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
id: string;
|
|
15
|
+
data: Record<string, any>;
|
|
16
|
+
position: number;
|
|
11
17
|
}
|
|
12
18
|
type Cells = Record<string, Cell>;
|
|
13
19
|
interface Row {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
id: string;
|
|
21
|
+
position: number;
|
|
22
|
+
cells: Cells;
|
|
17
23
|
}
|
|
18
24
|
type Rows = Record<string, Row>;
|
|
19
|
-
interface ElementData {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
interface Element {
|
|
25
|
-
id: number;
|
|
26
|
-
uid: string;
|
|
27
|
-
activityId: number;
|
|
28
|
-
repositoryId: number;
|
|
29
|
-
contentId: string;
|
|
30
|
-
contentSignature: string;
|
|
31
|
-
type: string;
|
|
32
|
-
position: number;
|
|
33
|
-
data: ElementData;
|
|
34
|
-
meta: {
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
};
|
|
37
|
-
refs: {
|
|
38
|
-
[key: string]: unknown;
|
|
39
|
-
};
|
|
40
|
-
linked: boolean;
|
|
41
|
-
detached: boolean;
|
|
42
|
-
createdAt: string;
|
|
43
|
-
updatedAt: string;
|
|
44
|
-
deletedAt: string | null;
|
|
25
|
+
interface ElementData extends common.ElementConfig {
|
|
26
|
+
tableId: string;
|
|
27
|
+
embeds: Embeds;
|
|
28
|
+
rows: Rows;
|
|
45
29
|
}
|
|
46
|
-
type DataInitializer =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
ssr: boolean;
|
|
52
|
-
isComposite?: boolean;
|
|
53
|
-
initState: DataInitializer;
|
|
54
|
-
Edit?: object;
|
|
55
|
-
TopToolbar?: object;
|
|
56
|
-
SideToolbar?: object;
|
|
57
|
-
Display?: object;
|
|
58
|
-
ui: {
|
|
59
|
-
icon: string;
|
|
60
|
-
forceFullWidth: boolean;
|
|
61
|
-
};
|
|
62
|
-
mocks?: {
|
|
63
|
-
displayContexts: Array<{
|
|
64
|
-
name: string;
|
|
65
|
-
data: any;
|
|
66
|
-
}>;
|
|
67
|
-
};
|
|
30
|
+
type DataInitializer = common.DataInitializer<ElementData>;
|
|
31
|
+
type Element = common.Element<ElementData>;
|
|
32
|
+
type ElementManifest = common.ElementManifest<ElementData>;
|
|
33
|
+
declare namespace utils_d_exports {
|
|
34
|
+
export { addCell, addEmbed, removeCell, removeEmbed };
|
|
68
35
|
}
|
|
69
|
-
|
|
70
36
|
declare function addCell(row: Row, cell: Cell): Cell;
|
|
71
|
-
declare function removeCell(row: Row, predicate?:
|
|
72
|
-
declare function addEmbed(embeds: Embeds, cellId: string, tableId: string):
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
data: {
|
|
77
|
-
tableId: string;
|
|
78
|
-
cellId: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
declare function removeEmbed(embeds: Embeds, predicate?: {}): any;
|
|
82
|
-
|
|
83
|
-
declare const utils_addCell: typeof addCell;
|
|
84
|
-
declare const utils_addEmbed: typeof addEmbed;
|
|
85
|
-
declare const utils_removeCell: typeof removeCell;
|
|
86
|
-
declare const utils_removeEmbed: typeof removeEmbed;
|
|
87
|
-
declare namespace utils {
|
|
88
|
-
export { utils_addCell as addCell, utils_addEmbed as addEmbed, utils_removeCell as removeCell, utils_removeEmbed as removeEmbed };
|
|
89
|
-
}
|
|
90
|
-
|
|
37
|
+
declare function removeCell(row: Row, predicate?: object): Cell | undefined;
|
|
38
|
+
declare function addEmbed(embeds: Embeds, cellId: string, tableId: string): Embed;
|
|
39
|
+
declare function removeEmbed(embeds: Embeds, predicate?: object): Embed | undefined;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/index.d.ts
|
|
91
42
|
declare const type = "TABLE";
|
|
92
43
|
declare const name = "Table";
|
|
93
44
|
declare const initState: DataInitializer;
|
|
94
45
|
declare const version = "1.0";
|
|
46
|
+
declare const isEmpty: (data: ElementData) => boolean;
|
|
47
|
+
declare const ai: AiConfig;
|
|
95
48
|
declare const manifest: ElementManifest;
|
|
96
|
-
|
|
97
|
-
export {
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Cell, Cells, DataInitializer, Direction, Element, ElementData, ElementManifest, Embed, Embeds, Row, Rows, ai, manifest as default, initState, isEmpty, name, type, utils_d_exports as utils, version };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as common from "@tailor-cms/cek-common";
|
|
2
|
+
import { AiConfig } from "@tailor-cms/cek-common";
|
|
3
|
+
|
|
4
|
+
//#region src/interfaces.d.ts
|
|
5
|
+
declare enum Direction {
|
|
6
|
+
Before = -1,
|
|
7
|
+
After = 1
|
|
8
|
+
}
|
|
9
|
+
type Embed = any;
|
|
10
|
+
type Embeds = Record<string, Embed>;
|
|
11
|
+
interface Cell {
|
|
12
|
+
id: string;
|
|
13
|
+
data: Record<string, any>;
|
|
14
|
+
position: number;
|
|
15
|
+
}
|
|
16
|
+
type Cells = Record<string, Cell>;
|
|
17
|
+
interface Row {
|
|
18
|
+
id: string;
|
|
19
|
+
position: number;
|
|
20
|
+
cells: Cells;
|
|
21
|
+
}
|
|
22
|
+
type Rows = Record<string, Row>;
|
|
23
|
+
interface ElementData extends common.ElementConfig {
|
|
24
|
+
tableId: string;
|
|
25
|
+
embeds: Embeds;
|
|
26
|
+
rows: Rows;
|
|
27
|
+
}
|
|
28
|
+
type DataInitializer = common.DataInitializer<ElementData>;
|
|
29
|
+
type Element = common.Element<ElementData>;
|
|
30
|
+
type ElementManifest = common.ElementManifest<ElementData>;
|
|
31
|
+
declare namespace utils_d_exports {
|
|
32
|
+
export { addCell, addEmbed, removeCell, removeEmbed };
|
|
33
|
+
}
|
|
34
|
+
declare function addCell(row: Row, cell: Cell): Cell;
|
|
35
|
+
declare function removeCell(row: Row, predicate?: object): Cell | undefined;
|
|
36
|
+
declare function addEmbed(embeds: Embeds, cellId: string, tableId: string): Embed;
|
|
37
|
+
declare function removeEmbed(embeds: Embeds, predicate?: object): Embed | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/index.d.ts
|
|
40
|
+
declare const type = "TABLE";
|
|
41
|
+
declare const name = "Table";
|
|
42
|
+
declare const initState: DataInitializer;
|
|
43
|
+
declare const version = "1.0";
|
|
44
|
+
declare const isEmpty: (data: ElementData) => boolean;
|
|
45
|
+
declare const ai: AiConfig;
|
|
46
|
+
declare const manifest: ElementManifest;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { Cell, Cells, DataInitializer, Direction, Element, ElementData, ElementManifest, Embed, Embeds, Row, Rows, ai, manifest as default, initState, isEmpty, name, type, utils_d_exports as utils, version };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
+
import { find, times } from "lodash-es";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
//#region src/utils.ts
|
|
5
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
addCell: () => addCell,
|
|
7
|
+
addEmbed: () => addEmbed,
|
|
8
|
+
removeCell: () => removeCell,
|
|
9
|
+
removeEmbed: () => removeEmbed
|
|
10
|
+
});
|
|
11
|
+
function addCell(row, cell) {
|
|
12
|
+
if (!row.cells) row.cells = {};
|
|
13
|
+
row.cells[cell.id] = cell;
|
|
14
|
+
return cell;
|
|
15
|
+
}
|
|
16
|
+
function removeCell(row, predicate = {}) {
|
|
17
|
+
const cell = find(row.cells, predicate);
|
|
18
|
+
if (!cell) return;
|
|
19
|
+
delete row.cells[cell.id];
|
|
20
|
+
return cell;
|
|
21
|
+
}
|
|
22
|
+
function addEmbed(embeds, cellId, tableId) {
|
|
23
|
+
const embed = {
|
|
24
|
+
id: cellId,
|
|
25
|
+
type: "JODIT_HTML",
|
|
26
|
+
embedded: true,
|
|
27
|
+
data: {
|
|
28
|
+
tableId,
|
|
29
|
+
cellId
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
embeds[cellId] = embed;
|
|
33
|
+
return embed;
|
|
34
|
+
}
|
|
35
|
+
function removeEmbed(embeds, predicate = {}) {
|
|
36
|
+
const embed = find(embeds, predicate);
|
|
37
|
+
if (!embed) return;
|
|
38
|
+
delete embeds[embed.id];
|
|
39
|
+
return embed;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/interfaces.ts
|
|
43
|
+
let Direction = /* @__PURE__ */ function(Direction) {
|
|
44
|
+
Direction[Direction["Before"] = -1] = "Before";
|
|
45
|
+
Direction[Direction["After"] = 1] = "After";
|
|
46
|
+
return Direction;
|
|
47
|
+
}({});
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/index.ts
|
|
50
|
+
const type = "TABLE";
|
|
51
|
+
const name = "Table";
|
|
52
|
+
const initState = () => {
|
|
53
|
+
const tableId = v4();
|
|
54
|
+
const embeds = {};
|
|
55
|
+
const rows = {};
|
|
56
|
+
times(2, (position) => {
|
|
57
|
+
const rowId = v4();
|
|
58
|
+
const row = {
|
|
59
|
+
id: rowId,
|
|
60
|
+
position,
|
|
61
|
+
cells: {}
|
|
62
|
+
};
|
|
63
|
+
rows[rowId] = row;
|
|
64
|
+
times(3, (position) => {
|
|
65
|
+
const cellId = v4();
|
|
66
|
+
addCell(row, {
|
|
67
|
+
id: cellId,
|
|
68
|
+
position,
|
|
69
|
+
data: {}
|
|
70
|
+
});
|
|
71
|
+
addEmbed(embeds, cellId, tableId);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
tableId,
|
|
76
|
+
embeds,
|
|
77
|
+
rows
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const version = "1.0";
|
|
81
|
+
const ui = {
|
|
82
|
+
icon: "mdi-table",
|
|
83
|
+
forceFullWidth: true
|
|
84
|
+
};
|
|
85
|
+
const isEmpty = (data) => !data?.rows || Object.keys(data.rows).length === 0;
|
|
86
|
+
const ai = {
|
|
87
|
+
Schema: {
|
|
88
|
+
type: "json_schema",
|
|
89
|
+
name: "ce_table",
|
|
90
|
+
schema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: { rows: {
|
|
93
|
+
type: "array",
|
|
94
|
+
minItems: 1,
|
|
95
|
+
items: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: { cells: {
|
|
98
|
+
type: "array",
|
|
99
|
+
minItems: 1,
|
|
100
|
+
items: { type: "string" }
|
|
101
|
+
} },
|
|
102
|
+
required: ["cells"],
|
|
103
|
+
additionalProperties: false
|
|
104
|
+
}
|
|
105
|
+
} },
|
|
106
|
+
required: ["rows"],
|
|
107
|
+
additionalProperties: false
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
getPrompt: () => `
|
|
111
|
+
Generate a table content element as an object with the following
|
|
112
|
+
properties:
|
|
113
|
+
{
|
|
114
|
+
"rows": [
|
|
115
|
+
{ "cells": ["", ""] }
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
where:
|
|
119
|
+
- 'rows' is an array of row objects.
|
|
120
|
+
- each row has a 'cells' array of plain text strings (one per cell).
|
|
121
|
+
Every row must have the same number of cells.
|
|
122
|
+
`,
|
|
123
|
+
processResponse: (val) => {
|
|
124
|
+
const tableId = v4();
|
|
125
|
+
const rows = {};
|
|
126
|
+
const embeds = {};
|
|
127
|
+
val.rows.forEach((row, rowPosition) => {
|
|
128
|
+
const rowId = v4();
|
|
129
|
+
rows[rowId] = {
|
|
130
|
+
id: rowId,
|
|
131
|
+
position: rowPosition,
|
|
132
|
+
cells: {}
|
|
133
|
+
};
|
|
134
|
+
row.cells.forEach((content, cellPosition) => {
|
|
135
|
+
const cellId = v4();
|
|
136
|
+
addCell(rows[rowId], {
|
|
137
|
+
id: cellId,
|
|
138
|
+
position: cellPosition,
|
|
139
|
+
data: {}
|
|
140
|
+
});
|
|
141
|
+
const embed = addEmbed(embeds, cellId, tableId);
|
|
142
|
+
embed.data.content = content;
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
tableId,
|
|
147
|
+
rows,
|
|
148
|
+
embeds
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const manifest = {
|
|
153
|
+
type,
|
|
154
|
+
version: "1.0",
|
|
155
|
+
name,
|
|
156
|
+
ssr: false,
|
|
157
|
+
isComposite: true,
|
|
158
|
+
initState,
|
|
159
|
+
isEmpty,
|
|
160
|
+
ui,
|
|
161
|
+
ai
|
|
162
|
+
};
|
|
163
|
+
//#endregion
|
|
164
|
+
export { Direction, ai, manifest as default, initState, isEmpty, name, type, utils_exports as utils, version };
|
package/package.json
CHANGED
|
@@ -3,52 +3,49 @@
|
|
|
3
3
|
"description": "Tailor CMS table manifest",
|
|
4
4
|
"author": "Studion <info@gostudion.com> (https://github.com/tailor-cms)",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0
|
|
6
|
+
"version": "2.0.0",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"import": "./dist/index.
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
10
|
"require": "./dist/index.cjs"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"main": "./dist/index.cjs",
|
|
14
|
-
"types": "./dist/index.d.
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@tailor-cms/eslint-config": "0.0.2",
|
|
20
|
-
"@types/lodash": "^4.17.14",
|
|
21
|
-
"tsup": "^8.3.6",
|
|
22
|
-
"typescript": "^5.7.3"
|
|
23
|
-
},
|
|
24
18
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
19
|
+
"@tailor-cms/cek-common": "2.0.1",
|
|
20
|
+
"lodash-es": "^4.18.1",
|
|
21
|
+
"uuid": "^14.0.0"
|
|
27
22
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@tailor-cms/eslint-config": "2.0.1",
|
|
25
|
+
"@types/lodash-es": "^4.17.12",
|
|
26
|
+
"tsdown": "^0.21.10",
|
|
27
|
+
"typescript": "^6.0.3"
|
|
28
|
+
},
|
|
29
|
+
"tsdown": {
|
|
30
|
+
"target": "node24",
|
|
36
31
|
"format": [
|
|
37
32
|
"cjs",
|
|
38
33
|
"esm"
|
|
39
|
-
]
|
|
40
|
-
"bundle": true,
|
|
41
|
-
"minify": false,
|
|
42
|
-
"clean": false,
|
|
43
|
-
"dts": true
|
|
34
|
+
]
|
|
44
35
|
},
|
|
45
36
|
"publishConfig": {
|
|
46
37
|
"access": "public"
|
|
47
38
|
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=24"
|
|
41
|
+
},
|
|
48
42
|
"scripts": {
|
|
49
|
-
"dev": "
|
|
50
|
-
"build": "
|
|
51
|
-
"lint": "eslint
|
|
52
|
-
"lint:fix": "pnpm lint --fix"
|
|
43
|
+
"dev": "tsdown --watch",
|
|
44
|
+
"build": "pnpm nuke:dist && tsdown",
|
|
45
|
+
"lint": "eslint .",
|
|
46
|
+
"lint:fix": "pnpm lint --fix",
|
|
47
|
+
"nuke": "pnpm dlx del-cli dist node_modules",
|
|
48
|
+
"nuke:dist": "pnpm dlx del-cli dist",
|
|
49
|
+
"prepublish": "pnpm build"
|
|
53
50
|
}
|
|
54
51
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
declare enum Direction {
|
|
2
|
-
Before = -1,
|
|
3
|
-
After = 1
|
|
4
|
-
}
|
|
5
|
-
type Embed = any;
|
|
6
|
-
type Embeds = Record<string, Embed>;
|
|
7
|
-
interface Cell {
|
|
8
|
-
id: string;
|
|
9
|
-
data: Record<string, any>;
|
|
10
|
-
position: number;
|
|
11
|
-
}
|
|
12
|
-
type Cells = Record<string, Cell>;
|
|
13
|
-
interface Row {
|
|
14
|
-
id: string;
|
|
15
|
-
position: number;
|
|
16
|
-
cells: Cells;
|
|
17
|
-
}
|
|
18
|
-
type Rows = Record<string, Row>;
|
|
19
|
-
interface ElementData {
|
|
20
|
-
tableId: string;
|
|
21
|
-
embeds: Embeds;
|
|
22
|
-
rows: Rows;
|
|
23
|
-
}
|
|
24
|
-
interface Element {
|
|
25
|
-
id: number;
|
|
26
|
-
uid: string;
|
|
27
|
-
activityId: number;
|
|
28
|
-
repositoryId: number;
|
|
29
|
-
contentId: string;
|
|
30
|
-
contentSignature: string;
|
|
31
|
-
type: string;
|
|
32
|
-
position: number;
|
|
33
|
-
data: ElementData;
|
|
34
|
-
meta: {
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
};
|
|
37
|
-
refs: {
|
|
38
|
-
[key: string]: unknown;
|
|
39
|
-
};
|
|
40
|
-
linked: boolean;
|
|
41
|
-
detached: boolean;
|
|
42
|
-
createdAt: string;
|
|
43
|
-
updatedAt: string;
|
|
44
|
-
deletedAt: string | null;
|
|
45
|
-
}
|
|
46
|
-
type DataInitializer = () => ElementData;
|
|
47
|
-
interface ElementManifest {
|
|
48
|
-
type: string;
|
|
49
|
-
version: string;
|
|
50
|
-
name: string;
|
|
51
|
-
ssr: boolean;
|
|
52
|
-
isComposite?: boolean;
|
|
53
|
-
initState: DataInitializer;
|
|
54
|
-
Edit?: object;
|
|
55
|
-
TopToolbar?: object;
|
|
56
|
-
SideToolbar?: object;
|
|
57
|
-
Display?: object;
|
|
58
|
-
ui: {
|
|
59
|
-
icon: string;
|
|
60
|
-
forceFullWidth: boolean;
|
|
61
|
-
};
|
|
62
|
-
mocks?: {
|
|
63
|
-
displayContexts: Array<{
|
|
64
|
-
name: string;
|
|
65
|
-
data: any;
|
|
66
|
-
}>;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
declare function addCell(row: Row, cell: Cell): Cell;
|
|
71
|
-
declare function removeCell(row: Row, predicate?: {}): Cell;
|
|
72
|
-
declare function addEmbed(embeds: Embeds, cellId: string, tableId: string): {
|
|
73
|
-
id: string;
|
|
74
|
-
type: string;
|
|
75
|
-
embedded: boolean;
|
|
76
|
-
data: {
|
|
77
|
-
tableId: string;
|
|
78
|
-
cellId: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
declare function removeEmbed(embeds: Embeds, predicate?: {}): any;
|
|
82
|
-
|
|
83
|
-
declare const utils_addCell: typeof addCell;
|
|
84
|
-
declare const utils_addEmbed: typeof addEmbed;
|
|
85
|
-
declare const utils_removeCell: typeof removeCell;
|
|
86
|
-
declare const utils_removeEmbed: typeof removeEmbed;
|
|
87
|
-
declare namespace utils {
|
|
88
|
-
export { utils_addCell as addCell, utils_addEmbed as addEmbed, utils_removeCell as removeCell, utils_removeEmbed as removeEmbed };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
declare const type = "TABLE";
|
|
92
|
-
declare const name = "Table";
|
|
93
|
-
declare const initState: DataInitializer;
|
|
94
|
-
declare const version = "1.0";
|
|
95
|
-
declare const manifest: ElementManifest;
|
|
96
|
-
|
|
97
|
-
export { type Cell, type Cells, type DataInitializer, Direction, type Element, type ElementData, type ElementManifest, type Embed, type Embeds, type Row, type Rows, manifest as default, initState, name, type, utils, version };
|
package/dist/index.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name2 in all)
|
|
4
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
import times from "lodash/times";
|
|
9
|
-
import { v4 as uuid } from "uuid";
|
|
10
|
-
|
|
11
|
-
// src/utils.ts
|
|
12
|
-
var utils_exports = {};
|
|
13
|
-
__export(utils_exports, {
|
|
14
|
-
addCell: () => addCell,
|
|
15
|
-
addEmbed: () => addEmbed,
|
|
16
|
-
removeCell: () => removeCell,
|
|
17
|
-
removeEmbed: () => removeEmbed
|
|
18
|
-
});
|
|
19
|
-
import find from "lodash/find";
|
|
20
|
-
function addCell(row, cell) {
|
|
21
|
-
if (!row.cells) row.cells = {};
|
|
22
|
-
row.cells[cell.id] = cell;
|
|
23
|
-
return cell;
|
|
24
|
-
}
|
|
25
|
-
function removeCell(row, predicate = {}) {
|
|
26
|
-
const cell = find(row.cells, predicate);
|
|
27
|
-
if (!cell) return;
|
|
28
|
-
delete row.cells[cell.id];
|
|
29
|
-
return cell;
|
|
30
|
-
}
|
|
31
|
-
function addEmbed(embeds, cellId, tableId) {
|
|
32
|
-
const embed = {
|
|
33
|
-
id: cellId,
|
|
34
|
-
type: "JODIT_HTML",
|
|
35
|
-
embedded: true,
|
|
36
|
-
data: { tableId, cellId }
|
|
37
|
-
};
|
|
38
|
-
embeds[cellId] = embed;
|
|
39
|
-
return embed;
|
|
40
|
-
}
|
|
41
|
-
function removeEmbed(embeds, predicate = {}) {
|
|
42
|
-
const embed = find(embeds, predicate);
|
|
43
|
-
if (!embed) return;
|
|
44
|
-
delete embeds[embed.id];
|
|
45
|
-
return embed;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/interfaces.ts
|
|
49
|
-
var Direction = /* @__PURE__ */ ((Direction2) => {
|
|
50
|
-
Direction2[Direction2["Before"] = -1] = "Before";
|
|
51
|
-
Direction2[Direction2["After"] = 1] = "After";
|
|
52
|
-
return Direction2;
|
|
53
|
-
})(Direction || {});
|
|
54
|
-
|
|
55
|
-
// src/index.ts
|
|
56
|
-
var type = "TABLE";
|
|
57
|
-
var name = "Table";
|
|
58
|
-
var initState = () => {
|
|
59
|
-
const tableId = uuid();
|
|
60
|
-
const embeds = {};
|
|
61
|
-
const rows = {};
|
|
62
|
-
times(2, (position) => {
|
|
63
|
-
const rowId = uuid();
|
|
64
|
-
const row = { id: rowId, position, cells: {} };
|
|
65
|
-
rows[rowId] = row;
|
|
66
|
-
times(3, (position2) => {
|
|
67
|
-
const cellId = uuid();
|
|
68
|
-
addCell(row, { id: cellId, position: position2, data: {} });
|
|
69
|
-
addEmbed(embeds, cellId, tableId);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
return { tableId, embeds, rows };
|
|
73
|
-
};
|
|
74
|
-
var version = "1.0";
|
|
75
|
-
var ui = {
|
|
76
|
-
// Display icon, https://pictogrammers.com/library/mdi/
|
|
77
|
-
icon: "mdi-table",
|
|
78
|
-
// Does element support only full width or can be used within layouts
|
|
79
|
-
// (e.g. 50/50 layout)
|
|
80
|
-
forceFullWidth: true
|
|
81
|
-
};
|
|
82
|
-
var manifest = {
|
|
83
|
-
type,
|
|
84
|
-
version: "1.0",
|
|
85
|
-
name,
|
|
86
|
-
ssr: false,
|
|
87
|
-
isComposite: true,
|
|
88
|
-
initState,
|
|
89
|
-
ui
|
|
90
|
-
};
|
|
91
|
-
var index_default = manifest;
|
|
92
|
-
export {
|
|
93
|
-
Direction,
|
|
94
|
-
index_default as default,
|
|
95
|
-
initState,
|
|
96
|
-
name,
|
|
97
|
-
type,
|
|
98
|
-
utils_exports as utils,
|
|
99
|
-
version
|
|
100
|
-
};
|